Share Some Scripts

philpw99 wrote on 8/28/2003, 12:13 PM
Here is some scripts I copied and modified from others. Many thanks to those who wrote and share the scripts so I can be much more productive.

Suppose you are a wedding video editor, you got 500 clips from 2 tapes. And you want to cut most clips into 10 or 5 second pieces. Now use this script, you can split all selected clips in just one click(You need to have Vegas 4.0d to run it):

---------------------

/**
* Program: SplitEvents.js
* Description: This script will split selected event into pieces for specified seconds
* Author: Philip
*
* Date: August 24, 2003
**/

import SonicFoundry.Vegas;
import System.Windows.Forms;
import Microsoft.Win32;

//time intervals for split events.

var Interval = "00:10:00";


try
{

var IncTime : Timecode = new Timecode(Interval);

// step through all selected video events:
for (var track in Vegas.Project.Tracks) {
for (var evnt in track.Events) {
if (!evnt.Selected || evnt.MediaType != MediaType.Video) continue;

evnt.Split(IncTime);


}
}

}

catch (errorMsg)
{
MessageBox.Show(errorMsg, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}

--------------------

OK, now your clips are all broken into pieces. You insert a new video track as the first track, and want to randomly put those pieces in a new order in that track, plus 1.5 second crossfade with each other. Using the following script, you just need to select some pieces, run the script, those pieces will be moved to the end of the first track(make sure that is a video track).

--------------------

/**
* Program: PutInFirstTrackEnd.js
* Description: This script will move selected events(except the one in first track) to
* the end of the first track. And automatically crossfade with the last event.
* Author: Philip
*
* Date: August 24, 2003
**/

import SonicFoundry.Vegas;
import System.Windows.Forms;
import Microsoft.Win32;

//time intervals for split events.
var playrate : double = 1;
var fadetime = new Timecode("00:00:01:15");

try
{


// step through all selected video events:
var FirstTrack : Track = Vegas.Project.Tracks.Item(0);

// step through all selected video events:
for (var track in Vegas.Project.Tracks) {
if( track.Index == 0) continue;

for (var evnt in track.Events) {
if (!evnt.Selected || evnt.MediaType != MediaType.Video) continue;

evnt.Copy(FirstTrack,FirstTrack.Length-fadetime);
track.Events.Remove(evnt);
}
}
}

catch (errorMsg)
{
MessageBox.Show(errorMsg, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}

/**
* Finds the currently selected event. Searches all tracks and returns the first
* even that is selected or null if no event is selected
* (Taken from the SonicFoundry Scripting FAQ)
*/
function FindSelectedEvent() : TrackEvent
{
var trackEnum = new Enumerator(Vegas.Project.Tracks);
while (!trackEnum.atEnd())
{
var track : Track = Track(trackEnum.item());
var eventEnum = new Enumerator(track.Events);
while (!eventEnum.atEnd())
{
var evnt : TrackEvent = TrackEvent(eventEnum.item());
if (evnt.Selected)
{
return evnt;
}
eventEnum.moveNext();
}
trackEnum.moveNext();
}
return null;
}

------------------------

When you keep doing this, you find out that because the pieces are moved to
the first track, therefore you get a lot of empty place in other tracks. Don't worry, just select the track that has this problem, run the following script, now the whole track will be arranged neatly, no more empty places. (Don't select track 1 though.)

--------------------

/**
* Program:
* Description: This script will Delete Empty Space Between Events In Selected Tracks
* Author: Philip
*
* Date: August 27, 2003
**/

import SonicFoundry.Vegas;
import System.Windows.Forms;
import Microsoft.Win32;

//time intervals for split events.
var septime = new Timecode("00:00:00:01");

try
{


// step through all selected video events:
var FirstTrack : Track = Vegas.Project.Tracks.Item(0);

// step through all selected video events:
for (var track in Vegas.Project.Tracks) {
if( !track.Selected) continue;
var tracktime = new Timecode(0);
for (var evnt in track.Events) {
evnt.Start=tracktime;
tracktime = tracktime + evnt.Length+septime;
}
}
}

catch (errorMsg)
{
MessageBox.Show(errorMsg, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}

-----------------------

Alright, now you have all pieces put in first track. It's the time to slow down all the video and put some Video FX in them. Select the ones you want to add effects and run the following script.

------------------------

/**
* Program: AddEffectAndSlowPlay.js
* Description: This script will add a FX and change playrate to the selected event
* Author: Philip
*
* Date: August 24, 2003
**/

import SonicFoundry.Vegas;
import System.Windows.Forms;
import Microsoft.Win32;

// This is the full name of the effect plug-in you want to add.
var plugInName = "Sonic Foundry Color Corrector (Secondary)";

// This is the name of the preset you want. Set this to null if you
// want the default preset.
var presetName = "Boost Mids";

var playrate = 0.5;

try
{
// step through all selected video events:
for (var track in Vegas.Project.Tracks) {
for (var evnt in track.Events) {
if (!evnt.Selected || evnt.MediaType != MediaType.Video) continue;

// Add FX
var fx = Vegas.VideoFX;

var plugIn = fx.GetChildByName(plugInName);
if (null == plugIn) {
throw "could not find a plug-in named: '" + plugInName + "'";
}

var effect = new Effect(plugIn);
evnt.Effects.Add(effect);
if (null != presetName) {
effect.Preset = presetName;
}

//Set playrate
evnt.AdjustPlaybackRate(playrate, 0);

}
}

}
catch (errorMsg)
{
MessageBox.Show(errorMsg, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}

------------------------

Finnally, the wedding video clips are all in places, it's time to do small adjustments and add music, transaction, titles, killer effects, etc... No more scripts needed, all the scripts here are just help you to build a barebone wedding MTV really quick (400 clips in about one hour) so you don't need to do those repetitive job that I had to do before discovering the true power of scripts.

Thank you Vegas Programmer, for making such a wonderful and powerful tool. And thank all the guys who post scripts here so I could copy and pirate :)

Comments

philpw99 wrote on 8/28/2003, 1:25 PM
One more script, this one can select all the events in selected tracks, quite useful sometimes.

/**
* Program:
* Description: This script will select all events In Selected Tracks
* Author: Philip
*
* Date: August 27, 2003
**/

import SonicFoundry.Vegas;
import System.Windows.Forms;
import Microsoft.Win32;

//time intervals for split events.

try
{


// step through all selected video events:

// step through all selected video events:
for (var track in Vegas.Project.Tracks) {
if( !track.Selected) continue;
for (var evnt in track.Events) {
evnt.Selected = true;
}
}
}

catch (errorMsg)
{
MessageBox.Show(errorMsg, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}

jetdv wrote on 8/28/2003, 1:46 PM
Well, your select script is shorter than mine and does all tracks (mine only does the first selected track but it was one of my first ones 4 months ago)

Couple of questions:
Are you sure about the 4.0d requirement? It looks like everything would also work in 4.0c.

In the second script, the "FindSelectedEvent" routine is not used?

Could you better explain how the first script could be used? I don't normally tape in good 10 second intervals. Just curious.




/**
* This script will select all events on the selected track
* Written By: Edward Troxel
* www.jetdv.com/tts
* Modified: 04/28/2003
**/

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


try {

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

var eventEnum = new Enumerator(track.Events);
while (!eventEnum.atEnd()) {
var evnt : TrackEvent = TrackEvent(eventEnum.item());

evnt.Selected = true;

eventEnum.moveNext();
}


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


philpw99 wrote on 8/28/2003, 11:20 PM
Well, I am not sure about the 4.0d requirement cause I just try to say use the latest one.

In the second sript, I forgot to delete the function. You are quite sharp to point it out.

The tapes I get from a wedding company come with many short clips. Some longer, some shorter, mostly around 10 sec. I devide them all in 10 secs so I just choose the good ones and change their length and position a little bit, then use second script to throw them to the first track. It's not a pretty approach, but the composing speed is blazing fast.

jetdv wrote on 8/28/2003, 11:26 PM
Thanks for the explanation.
philpw99 wrote on 8/31/2003, 9:55 PM
There are 2 scipts I have to update. They work better now.

/**
* Program: PutInFirstTrackEnd.js
* Description: This script will move selected events(except the one in first track) to
* the end of the first track. And automatically crossfade with the last event.
* Author: Philip
*
* Date: August 31, 2003
**/

import SonicFoundry.Vegas;
import System.Windows.Forms;
import Microsoft.Win32;

//time intervals for split events.
var playrate : double = 1;
var fadetime = new Timecode("00:00:01:15");


function DeleteEventInTrack (track)
{
var eventEnum = new Enumerator(track.Events);
var evnt: TrackEvent = TrackEvent(eventEnum.item());
do{
evnt = TrackEvent(eventEnum.item());

if (evnt.Selected)
{
//Remove events here
track.Events.Remove(evnt);
eventEnum = new Enumerator(track.Events);

}
else
eventEnum.moveNext();

}while (!eventEnum.atEnd());

}

try
{


// step through all selected video events:
var FirstTrack : Track = Vegas.Project.Tracks.Item(0);

if (FirstTrack.MediaType != MediaType.Video) throw("The first track is not a video track!");

// step through all selected video events:
for (var track in Vegas.Project.Tracks) {
if( track.Index == 0 || track.MediaType != MediaType.Video) continue;

for (var evnt in track.Events) {

if (!evnt.Selected) continue;

if(evnt.Length < new Timecode("06:00") || FirstTrack.Length == new Timecode(0) )
evnt.Copy(FirstTrack,FirstTrack.Length);
else
evnt.Copy(FirstTrack,FirstTrack.Length-fadetime);
}

DeleteEventInTrack(track);

}


}

catch (errorMsg)
{
MessageBox.Show(errorMsg, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}


========================

/**
* Program:
* Description: This script will Delete Empty Space Between Events In Selected Tracks
* Author: Philip
*
* Date: August 31, 2003
**/

import SonicFoundry.Vegas;
import System.Windows.Forms;
import Microsoft.Win32;

//time intervals for split events.

try
{


// step through all selected video events:
var FirstTrack : Track = Vegas.Project.Tracks.Item(0);

// step through all selected video events:
for (var track in Vegas.Project.Tracks) {
if( !track.Selected) continue;
var tracktime = new Timecode(0);
for (var evnt in track.Events) {
evnt.AdjustStartLength(tracktime,evnt.Length,true);
tracktime = tracktime + evnt.Length;
}
}
}

catch (errorMsg)
{
MessageBox.Show(errorMsg, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}


macdo wrote on 3/23/2004, 11:46 AM
I`ve a question about: Program: AddEffectAndSlowPlay.js
What happens with the contents of a clip when u decrease the playrate and keeps the same length?
How do u change the event length to show the same content from the original?


Thanks
-- ]\/[ /\ ( --
zoom wrote on 3/26/2004, 6:59 AM
Thanks Philip. These are great. I have a question about the PutInFirstTrackEnd script. How can I make it copy the audio track as well? I am new to scripting (in Vegas, at least) and I only work in Vegas intensively about three times a year, so it might be something simple I am missing.
I would like to use this to automate some interview footage - about 35 short interviews that need to be trimmed up and moved to the same track with a simple crossfade. But I need the audio to stay in sync.

-Tony