View Full Version : Close Gap Script


Jim Schuchmann
July 21st, 2010, 01:38 PM
I am having a problem trying to get this script to work

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

import Sony.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) {
var currTake = evnt.ActiveTake;
var CurrOffset = currTake.Offset;
evnt.Start = tracktime;
currTake.Offset = CurrOffset;
tracktime = tracktime + evnt.Length;
}
}
}

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

I have it installed in Vegas Pro 9e and when I run the script it says that "An error occured during execution."

Error 0x80131600
Details are
C:\ProgramFiles\Sony\VegasPro9.0\Script Menu\DeleteEmptySpaceBetweenEvents.js(1) : Invalid character.

Any help would be appreciated.

Edward Troxel
July 21st, 2010, 01:48 PM
Is that the entire script? What's on line 1 of your .js file? It should be /** so if you have something else there, delete it.

Jim Schuchmann
July 21st, 2010, 01:54 PM
That is the entire script. I checked and there was a space following/**. I removed it and it still reports the same error.

Edward Troxel
July 21st, 2010, 02:29 PM
This modified version worked for me. However, the problem I found was with the spelling of "currOffset" instead of "CurrOffset". Copy this version and replace your text with this:


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

import Sony.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) {
var currTake = evnt.ActiveTake;
var CurrOffset = currTake.Offset;
evnt.Start = tracktime;
currTake.Offset = CurrOffset;
tracktime = tracktime + evnt.Length;
}
}
}

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

Jim Schuchmann
July 21st, 2010, 02:41 PM
Thanks for your help Ed.

The first part of the problem that I was having was the fact that I was creating this script in a word program and not in "Notepad". When I would open the file in my word program, it all "looked" good. When I opened it in "Notepad", it showed machine language instead of the characters I had typed.

As a Newbie to scripting I now "know" that to create or modify a script you must use "Notepad". I wonder how many other newbies have made this mistake and given up on scripting.

Hope this helps some others out there.

Edward Troxel
July 21st, 2010, 02:47 PM
Yes, you definitely want to use a "plain text" editor. For those that have it, Visual Studio can make things even easier and you can set it up to do code completion for you - including the possibilities for Vegas. Makes it much easier when you can't think of the actual property name you want to get a list to choose from.