Script to lock events based on first event

johnmeyer wrote on 5/12/2008, 10:32 AM
This is a variation of my other script, based on a request from a user. This script will lock or un-lock all events on all selected tracks. The decision on whether to lock or un-lock is made based on the lock status of the first event. So, if the first event on the first selected track is un-locked, the script will un-lock ALL events on ALL selected tracks. If that first event is locked, then all events on all selected tracks are locked.

[Edit] Look further down in this thread for a better version of this script.


/**
* PURPOSE OF THIS SCRIPT:
*
* Locks or unlocks all events on selected track, based on the lock status
* of the first event on the first selected track.
*
* Copyright © John Meyer 2004
* Written: September 23, 2004
*
**/

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


try {
var first_time = true;
//Go through the list of Tracks
var trackEnum = new Enumerator(Vegas.Project.Tracks);
while (!trackEnum.atEnd()) {
var track : Track = Track(trackEnum.item());
var eventEnum = new Enumerator(track.Events);
var evnt : TrackEvent = TrackEvent(eventEnum.item());
if (track.Selected) {
if (first_time) {
var lockedevnt = false;
if (evnt.Locked == true) {
lockedevnt = true;
}
first_time = false;
}

//Go through the list of Events
while (!eventEnum.atEnd()) {
evnt = TrackEvent(eventEnum.item());
if (lockedevnt) {
evnt.Locked = true;
}
else {
evnt.Locked = false;
}
eventEnum.moveNext();
} // End While eventEnum
} // End if track selected
trackEnum.moveNext();
} // End While trackEnum
if (lockedevnt) {
MessageBox.Show("Events on selected tracks are all locked.","Completed",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
else {
MessageBox.Show("Events on selected tracks are all UN-locked.","Completed",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
eventEnum.moveNext();

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

Comments

cold ones wrote on 5/12/2008, 10:55 AM
Thanks, it's great, thanks again! For my use, I altered one little bit of it to make it do the OPPOSITE lock state of the first clip---

if (track.Selected) {
if (first_time) {
var lockedevnt = false;
if (evnt.Locked == true) {
lockedevnt = false;
}
else {
lockedevnt = true
}
first_time = false;
}

Hope this makes sense ;)
johnmeyer wrote on 5/12/2008, 10:58 AM
Ah, you wanted a toggle. That makes much more sense because you don't even have to set the initial event state. I really like scripts that work this way. Congratulations on a very good idea!!
johnmeyer wrote on 5/12/2008, 11:05 AM
Here's the script, based on J Schultz amazingly good idea, which simply toggles the state of all events on all selected tracks, based on the lock status of the first event on the first selected track. Thus, you don't even need to set an initial state: just run the script and the events will be locked the first time you run it, and then un-locked when you run the same script again, and so on.


/**
* PURPOSE OF THIS SCRIPT:
*
* Toggles lock status of all events on selected tracks, based on the lock status
* of the first event on the first selected track. If first event is locked,
* all events and all selected tracks are un-locked. If that first event on the
* first selected track is un-locked, then all events on all selected
* tracks are locked.
*
* Copyright © John Meyer 2008
* Written: May 12, 2008
*
**/

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


try {
var first_time = true;
//Go through the list of Tracks
var trackEnum = new Enumerator(Vegas.Project.Tracks);
while (!trackEnum.atEnd()) {
var track : Track = Track(trackEnum.item());
var eventEnum = new Enumerator(track.Events);
var evnt : TrackEvent = TrackEvent(eventEnum.item());
if (track.Selected) {
if (first_time) {
var lockedevnt = true;
if (evnt.Locked == true) {
lockedevnt = false;
}
first_time = false;
}

//Go through the list of Events
while (!eventEnum.atEnd()) {
evnt = TrackEvent(eventEnum.item());
if (lockedevnt) {
evnt.Locked = true;
}
else {
evnt.Locked = false;
}
eventEnum.moveNext();
} // End While eventEnum
} // End if track selected
trackEnum.moveNext();
} // End While trackEnum
if (lockedevnt) {
MessageBox.Show("Events on selected tracks are all locked.","Completed",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
else {
MessageBox.Show("Events on selected tracks are all UN-locked.","Completed",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
eventEnum.moveNext();

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



cold ones wrote on 5/12/2008, 11:08 AM
John

I'm trying to understand scripting, appreciate you taking the time!

I've been wondering how to do the same thing to scripts like the "Add Timecode to All Media"---a simple toggle there could turnTimecode on and off, for instance, which I do a lot at certain points in a project.

One more question---if I didn't need a MessageBox at the completion of your Track Lock script, what would i do? (I've tried cutting a few lines at the end but that causes errors---good thing I'm not a surgeon)
johnmeyer wrote on 5/12/2008, 11:23 AM
---if I didn't need a MessageBox at the completion of your Track Lock script, what would i do?

Just delete the MessageBox.Show lines.

Or, you can delete the entire if logic:


if (lockedevnt) {
MessageBox.Show("Events on selected tracks are all locked.","Completed",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
else {
MessageBox.Show("Events on selected tracks are all UN-locked.","Completed",MessageBoxButtons.OK,MessageBoxIcon.Information);
}



For ideas on assigning fX, go to this page:

Folding Rain

and scroll down until you find the links to three free Vegas scripts (they are near the bottom of the page). The MultiFXAssigner is a really cool script. It does way more than you want, but it will show you how it's done.

[Edit]
And here's a link to the old Vegas script API:

Vegas Script API