Event to Subclip Script

johnmeyer wrote on 2/1/2007, 2:02 PM
This script takes selected events and turns them into subclips.

John
/*

Script: Events To Subclips.js
Based on scripts by Sony Media Software & John Rofrano

This script creates Subclips from selected events,
and then places them in the root mediabin.

This script is only supported by Vegas version 6.0c and above.

Converted from C# to Jscript, and modified to work with
events instead of regions by John H. Meyer on January 31, 2007.

*/

import System;
import System.Text;
import System.Collections;
import System.Windows.Forms;
import Sony.Vegas;

try {
var processedClipCount : int = 0;
var trackEnum = new Enumerator(Vegas.Project.Tracks);

while (!trackEnum.atEnd()) { // Go through all tracks

var track : Track = Track(trackEnum.item());
var eventEnum = new Enumerator(track.Events);
if (!track.IsVideo()) { // Only process video tracks
trackEnum.moveNext();
continue;
}
while (!eventEnum.atEnd() ) { // Go through each event on this track
var evnt : TrackEvent = TrackEvent(eventEnum.item());

if (!evnt.Selected) { // Only process selected events
eventEnum.moveNext();
continue;
}

var activeTake : Take = evnt.ActiveTake;

if (null == activeTake) { // Only process events with active takes.
eventEnum.moveNext();
continue;
}

var media : Media = activeTake.Media;
if (null == media) {
eventEnum.moveNext();
continue;
}

// Initialize variables
var takeOffset : Timecode = activeTake.Offset;
var labelprefix : String;

var clipName : String = System.IO.Path.GetFileName(media.FilePath);

// Append counter to media name and pad with leading zeros so media can be sorted in MediaBin.
labelprefix = RepeatedConcat("0",3-processedClipCount.ToString().length) + processedClipCount.ToString() + " - " + clipName;

// Create the Subclip
// Comment out following line and instead use second line if you want timecode prefix
var clip = new Subclip(media.FilePath, takeOffset, evnt.Length, false, labelprefix);
// var clip = new Subclip(media.FilePath, takeOffset, evnt.Length, false, takeOffset.ToString() + " - " + clipName);

Vegas.Project.MediaPool.RootMediaBin.Add(clip);
processedClipCount++;

eventEnum.moveNext();
} // End While Eventenum

trackEnum.moveNext();
} // End While TrackEnum

MessageBox.Show(processedClipCount.toString() + " regions/subclips processed.");

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

function RepeatedConcat(concatStr,intCount) {
var arrTmp = new Array(intCount+1);
return arrTmp.join(concatStr);
}


/* END OF SCRIPT */

Comments

Frank Z wrote on 3/18/2007, 12:03 PM
Instead of RepeatedConcat, you can also do String.Format("0:000", processedClipCount)

less overhead. Cool script. I'm surprised that alot of automatic subclip functionality is missing from the base product. Still love it though.

By the way, do scripts work in the lower Vegas products?
jetdv wrote on 3/18/2007, 1:53 PM
By the way, do scripts work in the lower Vegas products?

No. Scripting does not work in the Movie Studio versions.