I'm using the "Delete from cursor to event start" script, but it either has a bug or something changed in Vegas 9.0d or earlier that doesn't make it behave as it should.
When you place the cursor where you want the event to start and you execute the script, it's suppose to slice the event at that point, then move the cursor to the beginning of the event and also move all the events at the right of the current event to the left, in a ripple way. But the way it's working now, instead of moving the events at the right, it slips all of them by the same time length that you removed from the event you were slicing, so you get all events to the end with the mark somewhere on the top indicate that they were slipped, as if you would have moved the mouse inside the event while pressing Alt, except you didn't. I'm pasting the whole script below, can somebody please tell me what's wrong? And also can someone please tell me how to modify it to make a second script that will delete from the cursor to the end of the event?
Thanks
/**
* 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
*
**/
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, true); // 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;
}
eventEnum.moveNext(); // Go to next event on this timeline.
}
return EventFound;
}
When you place the cursor where you want the event to start and you execute the script, it's suppose to slice the event at that point, then move the cursor to the beginning of the event and also move all the events at the right of the current event to the left, in a ripple way. But the way it's working now, instead of moving the events at the right, it slips all of them by the same time length that you removed from the event you were slicing, so you get all events to the end with the mark somewhere on the top indicate that they were slipped, as if you would have moved the mouse inside the event while pressing Alt, except you didn't. I'm pasting the whole script below, can somebody please tell me what's wrong? And also can someone please tell me how to modify it to make a second script that will delete from the cursor to the end of the event?
Thanks
/**
* 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
*
**/
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, true); // 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;
}
eventEnum.moveNext(); // Go to next event on this timeline.
}
return EventFound;
}