Delete to event start (Vegas 6)

johnmeyer wrote on 5/31/2006, 9:00 AM
This is the second script for cuts-only editing. I have described elsewhere how to use the three scripts in this suite. This has been updated to Vegas 6, and also now supports multiple takes.
/** 
* PURPOSE OF THIS SCRIPT:
*
* Delete frames from cursor to start of event, and then move all events to the left by n frames.
*
*
* A video track must be selected. If an audio track is selected, nothing happens.
* The video event on the track that lies beneath the cursor
* will be shortened from the cursor to the start of the event.
* If the track beneath the video track contains audio, the audio event in that track
* that lies beneath the cursor will also be shortened by the same number of frames.
*
* Copyright © John Meyer 2004
* Written: June 4, 2003
* Updated: September 23, 2004
* Updated to work with Vegas 6.0d on February 4, 2006
* Updated: May 26, 2006 // Now ripples all takes for each event
*
**/

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

try {

//Global declarations
var dStart : Double;
var dLength : Double;
var dCursor : Double;
var trackEnum : Enumerator;
var evnt : TrackEvent;

var EventBegin : Timecode = Vegas.Cursor; // Use this to move cursor position.
var track = FindSelectedTrack(); // Use this function to find the first selected track.
var eventEnum = new Enumerator(track.Events);
var BeyondCursor : boolean = false; // This flag used to notify if event is to right of cursor.

if (track.IsVideo()) { // Proceed only if selected track is video track.

if ( TrimEventAtCursor() ) { // Function that trims event and moves all remaining events on track left.

// Get set to look at track directly below the video track.
BeyondCursor = false;
trackEnum.moveNext(); // Go to next track.

if (!trackEnum.atEnd()) { // Only proceed if there is a track below the video track.
track = Track(trackEnum.item()); // When doing the first track (above), these two lines were executed
eventEnum = new Enumerator(track.Events); // in the FindSelectedTrack() function.
if (track.IsAudio()) { // Only trim the event if this is an audio track.
TrimEventAtCursor();
}
}
}
}
Vegas.UpdateUI();

// Move cursor to start of selected event (cursor stays at same media location).
Vegas.Cursor = EventBegin; // Remove this line to keep cursor in same location.

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

// End of main program



// Beginning of functions

function FindSelectedTrack() : Track {
trackEnum = new Enumerator(Vegas.Project.Tracks);
while (!trackEnum.atEnd()) {
var track : Track = Track(trackEnum.item());

if (track.Selected) {
return track;
}
trackEnum.moveNext();
}
return null;
}


/**
*
* The following function finds the event on the selected track
* that lies under the cursor. It also deselects all other events.
*
**/

function TrimEventAtCursor() {

var EventFound : boolean = false; // Function returns false if no video media under cursor.
var DeleteFrames : Timecode = new Timecode("00:00:00:00");
var DeleteTime : Double = DeleteFrames.ToMilliseconds();

dCursor = Vegas.Cursor.ToMilliseconds(); // Remember the cursor position.

//Go through each event on the track.

while (!eventEnum.atEnd()) {
evnt = TrackEvent(eventEnum.item());
evnt.Selected = false; // De-select the event


// Get the event's start and length timecode, in milliseconds.
dStart = evnt.Start.ToMilliseconds();
dLength = evnt.Length.ToMilliseconds();


if (BeyondCursor) { // Move, but don't truncate events to the right of the event under the cursor.
// evnt.Start=evnt.Start-DeleteFrames; // Use this line for versions of Vegas prior to 4.0d
evnt.AdjustStartLength(evnt.Start-DeleteFrames, evnt.Length, false); // Use this line with 4.0d and beyond.
}

/**
* If the cursor timecode is between the beginning and end of the
* event timecodes, then select the event, and trim start by n frames.
* Move selected event and all events to right of cursor to left by n frames.
**/

if ( (dCursor >= dStart) && ( dCursor < (dLength + dStart) ) ) {
evnt.Selected = true; // Select this event.
EventFound = true;
BeyondCursor = true; // Remaining events are to right of cursor.
DeleteFrames = Vegas.Cursor - Timecode(evnt.Start);
DeleteTime = DeleteFrames.ToMilliseconds();
EventBegin = evnt.Start;
dLength = dLength - DeleteTime;

// Next two lines truncate start of event, and then move it left
// by the same amount that it was truncated.
evnt.AdjustStartLength(new Timecode(dStart), new Timecode(dLength), false);
// evnt.ActiveTake.Offset = DeleteFrames+evnt.ActiveTake.Offset+ Timecode.FromSeconds(1);
for (var i=evnt.Takes.Count - 1; i >= 0; i--) {
evnt.Takes[i].Offset = DeleteFrames+evnt.Takes[i].Offset; // Make change for ALL takes.
} // End for i

}

eventEnum.moveNext(); // Go to next event on this timeline.

}
return EventFound;
}

Comments

No comments yet - be the first to write a comment...