Need script performance tip

johnmeyer wrote on 8/7/2013, 5:43 PM
I have several script that iterate through every event on a track. They usually work just fine. However, I have a project with 3,500 events, half of these on one track, and even my 3.2 GHz i7 computer takes over thirty seconds to get through all of them. I therefore conclude that I must be using a very inefficient script construct. The simplest script function is shown below. All it does is to select the event under the current cursor location on the first selected track, and then deselect all other events on that track.

Is there a more efficient way to do this using jscript? If I created a cs version of the script, would it be faster? I obviously could try to compile it, but I don't do that kind of programming any more and the one computer that has a compiler installation hasn't bee used for a decade.

Thanks for any help or hints you can provide.

function SelectEventAtCursor() {

var EventFound : boolean = false; // Function returns false if no video media under cursor.

dCursor = Vegas.Cursor.ToMilliseconds(); // Remember the cursor position.

//Go through each event on the track.

while (!eventEnum.atEnd()) {
evnt = TrackEvent(eventEnum.item());
evnt.Selected = false; // De-select the event

// Get the event's start and length timecode, in milliseconds.
dStart = evnt.Start.ToMilliseconds();
dLength = evnt.Length.ToMilliseconds();

* If the cursor timecode is between the beginning and end of the
* event timecodes, then select the event.

if ( (dCursor >= dStart) && ( dCursor < (dLength + dStart) ) ) {
evnt.Selected = true; // Select this event.
EventFound = true;
CurrentEvnt = evnt;
eventEnum.moveNext(); // Go to next event on this timeline.

return EventFound;


Gary James wrote on 8/8/2013, 7:04 AM
I have similar code in Timeline Tools that sets the Selected property in a single Event while disabling it in all other Events on a track; and the logic isn't that much different than your code example. However, in my largest slideshow project with over 1200 Events, the change happens in just a second or so.

So what's the difference? My program was written using C#. And my code is compiled into a Sony Vegas compliant Extension DLL using Visual Studio 2010. I would guess it's compiled code vs. script that's causing your code to run so slowly. By the way, you can get a free version of Visual Studio Express from Microsoft that will let you compile your scripts into DLL's so they'll run faster. You don't have to go all the way and create a Vegas Extension.

Rosebud wrote on 8/8/2013, 11:59 PM
why not to simply click on the event ? All other event will be deselected.
johnmeyer wrote on 8/12/2013, 4:09 PM
The script is part of a suite of scripts that I use for "cuts-only" editing, so selecting the event is a trivial part of the overall package.

I found that the problem is entirely with Vegas 7.0d. The same script, operating on the same project, executes instantly on 8.0c. I use 7.0d because I have an old version of Excalibur that runs on that version. However, now that I know the problem is a bug in 7.0d, I can proceed.

A .cs version of the script had the same performance problems.