-
Randal Petryshyn
March 25, 2014 at 4:32 pmHi Matt
Did I bugger something up?
Thanks
Randalusing System;
using Sony.Vegas;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Drawing;class EntryPoint
{
//Change this to true if you want to default to all tracks
const bool ALLTRACKS = false;//Change this to false if you want to split audio tracks as well
const bool VIDEOONLY = true;//This is the length of frames you want each event to keep
const int FRAMELENGTHTORETAIN = 1;public void FromVegas(Vegas vegas)
{
DeselectAllEvents(vegas);
List TracksUsed = SplitFrameAtMarkers(vegas);
DeleteAllButSelected(TracksUsed);
}private List SplitFrameAtMarkers(Vegas vegas)
{List TracksToUse = GetTracksToModify(ALLTRACKS, vegas);
foreach (Marker m in vegas.Project.Markers)
{
List EventsAtMarker = GetEventsAtPosition(m.Position, TracksToUse);
foreach(TrackEvent ev in EventsAtMarker)
{
ev.Split(m.Position - ev.Start);
TrackEvent backhalf = GetNewlySplitEvent(ev);
backhalf.Split(Timecode.FromFrames((FRAMELENGTHTORETAIN));
backhalf.Selected = true;
}
}
return TracksToUse;
}//Get the tracks to modify by choosing selected tracks
//or all of them if ALLTRACKS is true.
//If there are no tracks selected the default will be the first track only.
private List GetTracksToModify(bool ALLTRACKS, Vegas vegas)
{
List tracks = new List();
foreach(Track t in vegas.Project.Tracks)
{
if (VIDEOONLY && !t.IsVideo()) continue;
if (t.Selected || ALLTRACKS) tracks.Add(t);
}
if (tracks.Count == 0) tracks.Add(vegas.Project.Tracks[0]);return tracks;
}private List GetEventsAtPosition(Timecode position,List tracks)
{
List events = new List();
foreach(Track t in tracks)
{
foreach(TrackEvent ev in t.Events)
{
if (ev.Start <= position && ev.End >= position)
events.Add(ev);
}
}
return events;
}private TrackEvent GetNewlySplitEvent(TrackEvent firsthalf)
{
return firsthalf.Track.Events[firsthalf.Index + 1];
}private void DeselectAllEvents(Vegas vegas)
{
foreach(Track t in vegas.Project.Tracks)
{
foreach(TrackEvent ev in t.Events)
{
ev.Selected = false;
}
}
}private void DeleteAllButSelected(List modifiedtracks)
{
List toremove = new List();
foreach (Track t in modifiedtracks)
{
foreach (TrackEvent ev in t.Events)
{
if (!ev.Selected) toremove.Add(ev);
}
}
foreach (TrackEvent ev in toremove)
{
ev.Track.Events.Remove(ev);
}
}}
-
Matt Carlson
March 25, 2014 at 5:53 pmNo you did not screw it up I did. The new changed line somehow has an extra parenthesis.
It should read:
backhalf.Split(Timecode.FromFrames(FRAMELENGTHTORETAIN));
Note the one left parenthesis in front of FRAMELENGTHTORETAIN.
The line I gave you was:
backhalf.Split(Timecode.FromFrames((FRAMELENGTHTORETAIN));
which has two parentheses before FRAMELENGTHTORETAIN. I am not sure how that happened but that creates the odd number of parentheses that caused the error.
Here is the working script with the change (I should have just done this originally….)
7291_keeponlyframesatmarkers.cs.zip
-
Randal Petryshyn
March 25, 2014 at 8:46 pm -
Matt Carlson
March 25, 2014 at 8:54 pmDo you mean close the gaps between the events that remain?
Also you might as well throw it all at me…
Do you want the markers removed etc?
Are there audio any audio event considerations?Your timeline looks like all your markers are at equal intervals. If you just want to grab every nth frame from an event and string them together the script can be simplified and markers could be taken out of the process completely.
-
Randal Petryshyn
March 25, 2014 at 9:04 pmYou got it Matt! Close the gaps, and remove the markers. If you could delete the audio stream completely it would be great!
Thanks
Randal -
Matt Carlson
March 26, 2014 at 12:07 amHere is the next version. It will close gaps, delete markers, and hopefully delete all the right audio events.
7292_keeponlyframesatmarkerspluscleanup.cs.zip
I am not sure if you saw the last edit of my previous post about all of your markers being at intervals. There are always dozens of ways to skin a cat programming wise. As your need to automate tasks grows graduating from using scripts to using extension windows will save you a ton of time.
Send me an email at
blackstingproductions@gmail.com
if you need more revisions or want to discuss what you think you need from a script and what you actually need from a script.
-
Randal Petryshyn
March 26, 2014 at 1:43 amIt worked very well! I really appreciate the help. Can I paypal you a case of beer?
Thanks
Randal -
Matt Carlson
March 26, 2014 at 3:34 amI am glad it worked. No beer is necessary :). I have stared down the barrel of an annoyingly repetitive editing task before and know what a relief it is to have a one button push answer.
-
Randal Petryshyn
March 26, 2014 at 5:21 amWell I really do appreciate your efforts and willingness to help. I hope there is something I can do for you at some point. You are a kind soul.
Thanks
Randal
Reply to this Discussion! Login or Sign Up

