Cut events at markers

johnmeyer wrote on 3/21/2007, 8:03 PM
I couldn't quite get a commercial script to do what I wanted, so I put together this very simple script. It will cut the events on the first selected track at the marker locations. I wasn't interested in other tracks, but it would be easy to extend the script to cut events on other tracks. Also, I was in a BIG hurry when I wrote this, and I couldn't remember if the event enumeration changes after an event is split, so I start over at the beginning of the event list after each and every cut. It's very crude and inefficient, but plenty good enough for what I needed. Should provide a nice starting point for someone that wants something more sophisticated, or perhaps whet their appetite for the more polished features found in the commercial Vegas scripts.

/**
* This script splits events at each marker.
*
* By John Meyer 3/21/2007
*
**/

import System;
import System.IO;
import System.Windows.Forms;
import Sony.Vegas;


try {

var track = FindSelectedTrack();
var markerEnum = new Enumerator(Vegas.Project.Markers); // Start going through all the markers

while (!markerEnum.atEnd()) { // Keep going until last marker
var MyMarker = markerEnum.item();
var eventEnum = new Enumerator(track.Events);

while (!eventEnum.atEnd()) {
var evnt = (eventEnum.item())

if (evnt.Start < MyMarker.Position && evnt.End > MyMarker.Position) {
evnt.Split (MyMarker.Position - evnt.Start);
break; //Once an event is split, enumeration has changed. Start over.
}

eventEnum.moveNext(); // Go to next event on this timeline.

}
markerEnum.moveNext(); // Get next marker
}


} catch (e) {
MessageBox.Show(e);
}


function FindSelectedTrack() : Track {
var trackEnum = new Enumerator(Vegas.Project.Tracks);
while (!trackEnum.atEnd()) {
var track : Track = Track(trackEnum.item());
if (track.Selected) {
return track;
}
trackEnum.moveNext();
}
return null;
}


Comments

JohnnyRoy wrote on 3/24/2007, 6:46 AM
> I couldn't quite get a commercial script to do what I wanted, so I put together this very simple script.

Did you look at Ultimate S2 or US3 Split Events at Markers function? It accomplishes the same thing you're doing here.

> Also, I was in a BIG hurry when I wrote this, and I couldn't remember if the event enumeration changes after an event is split, so I start over at the beginning of the event list after each and every cut.

Any time you modify the contents of a collection the enumeration changes. As a general rule of thumb, you should make a copy of any collection you intend to change while enumerating over it.

~jr