Script Request: add regions and event names

CDM wrote on 4/11/2005, 3:25 PM
Hi -
I'm wondering how complicated it would be for someone to write the following script:
I have a track with a bunch of songs as single events. Each event is named with the title of the song. I would like a script to add a region around each event and name it with the name of the event. This way I can use my batch converter script to render all the regions as separate files.

thanks in advance.

Comments

johnmeyer wrote on 4/11/2005, 5:51 PM
This will do exactly what you want. To use it, copy it, and then paste into Word. Replace the line breaks with paragraph marks, and then save as a text file with the extension .js.

Please note that, as described in the remarks at the beginning of the script, if you have multiple events that come from the same media file, the region names will all be identical.

=====================
/**
* This script will add regions for all events on the selected track,
* and name those regions to the event's media file name.
*
* If more than one event comes from the same media, this will result in
* duplicate region names.
*
* By John Meyer 4/11/2005
*
**/

import System;
import System.IO;
import System.Windows.Forms;
import Microsoft.Win32;
import Sony.Vegas;
var evnt : TrackEvent;
var myRegion : Region;
var RegionNumber;
var RegionName : String;


try {

//Find the selected event
var track = FindSelectedTrack();
if (null == track)
throw "no selected track";

var eventEnum = new Enumerator(track.Events);
while (!eventEnum.atEnd()) {
evnt = TrackEvent(eventEnum.item());
var MyFilePath = evnt.ActiveTake.MediaPath;
var extFileName = Path.GetFileName(MyFilePath);
var baseFileName = Path.GetFileNameWithoutExtension(extFileName); // Media file name for this event

myRegion = new Region(evnt.Start,evnt.Length,baseFileName); //Insert a region over this event
Vegas.Project.Regions.Add(myRegion);
eventEnum.moveNext();
RegionNumber++;
}

} 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;
}


CDM wrote on 4/12/2005, 11:48 AM
thanks very much!
johnmeyer wrote on 4/12/2005, 8:33 PM
Let me know if it works.
ElRobboz wrote on 10/27/2018, 10:31 PM

John, you'll be pleased to know that your awesome script works perfectly in Vegas Pro 12 (current version is v16) 13 years after you published this solution! Thank you so much for this as I have wanted to carry out this simple task for a very long time! Cheers, mate! 👏