Comments

johnmeyer wrote on 1/27/2011, 10:32 AM
You already asked this question three months ago, and I responded with a script:

Script to select event to the left or right?
Sebaz wrote on 2/1/2011, 7:45 AM
LOL, sorry John, my memory sucks.
dalemccl wrote on 2/20/2011, 5:33 PM
EDIT: Please disregard the rest of my post below. In another forum a suggestion was made for an easy way to accomplish what I want without a script.
----------------------------------------------------------------------------------------------------------------
The title of this thread asks exactly what I have been wanting to ask about -- a script to delete from the cursor to the end of the event that the cursor is positioned over. This would act the same as dragging the right edge of the event toward the left to trim off the unwanted end of an event.

I found a script to delete from the cursor to the beginning of the event, but have never found one to delete from the cursor to the end of the event.

I may have misunderstood, but although this thread's subject line contains "delete from cursor to end", the reply to the question points to an older post that seems to discuss scripts to *select* an event to the left of, or to the right of, the event where the cursor is located.

I would find it very useful to have a Vegas Pro 10 compatible script that deletes from the cursor to the end of the event. That would go along nicely with the existing script that deletes from the cursor to the beginning of the event.

If there is such a script, I'd appreciate someone pointing me to it.

Thanks.
Marco. wrote on 10/10/2011, 1:14 PM
Not a script but a simple tool which does delete part of an event from cursor to beginning of the event or from cursor to end of event just by using two different hot keys. It works in any Vegas Pro and any Movie Studio version. Available here: .


johnmeyer wrote on 10/28/2011, 12:33 PM
He asked me via PM to modify my script and eventually I agreed. Here is the result:

/** 
* PURPOSE OF THIS SCRIPT:
*
* Delete frames from cursor to end 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: October 23, 2011 // Changed to delete from cursor to event end
*
**/

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

try {

//Global declarations
var dStart : Double;
var dEnd : Double;
var dLength : Double;
var dCursor : Double;
var trackEnum : Enumerator;
var evnt : TrackEvent;
var delevnt : 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:01");
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.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 end 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 = Timecode(evnt.End) - Vegas.Cursor;


DeleteTime = DeleteFrames.ToMilliseconds();
EventBegin = evnt.Start;
dLength = dLength - DeleteTime ;
// Next two lines truncate end of event
evnt.AdjustStartLength(new Timecode(dStart), new Timecode(dLength), true);
}

eventEnum.moveNext(); // Go to next event on this timeline.
//Vegas.UpdateUI();
//MessageBox.Show("stop");
}
return EventFound;
}
NickHope wrote on 9/9/2016, 4:02 AM

Does anyone know how to modify John's script to leave the cursor where it is after the cut (i.e. at the cut), rather than it moving to the beginning of the event?

NickHope wrote on 9/9/2016, 4:38 AM

...or maybe there's a way to do it slightly differently in a script by splitting the event under the cursor then deleting the newly-created event immediately to the right of the cursor (like how Marco's CUT does it)?

Marco. wrote on 9/9/2016, 5:35 AM

Are you sure you'd still need this kind of script or macro solutions? Isn't Vegas' internal trim feature doing this meanwhile? At least me I meanwhile use Alt+[ and Alt+] most of the time or SEMW Extensions to do that job.

Quitter wrote on 9/9/2016, 6:19 AM

it does not require a script for this job in Vegas 13, as Marco said

Alt+ ß = Delete from cursor to event start
Alt+´   = Delete from cursor to event end

contrary to manual, which says:
Alt+[   and    Alt+]

 

Last changed by Quitter on 9/9/2016, 6:43 AM, changed a total of 1 times.

Camcorder: Sony CX 520 VE
Hardware:   Acer NG-A717-72G-71YD, Win 11 , i7-8750 H, 16GB, GTX 1060 6GB, 250GB SSD, 1TB HDD
NLE:  Sony Vegas Pro 13.0 Build 453
            Vegas Pro 14.0 Build 270
            Vegas Pro 21.0 Build 300

 

Marco. wrote on 9/9/2016, 6:28 AM

Alt+ß and Alt+´ is for German version of Vegas Pro and keyboards only. Alt+[ and Alt+] is for the English versions.

Quitter wrote on 9/9/2016, 6:59 AM

You're right, my fault

Camcorder: Sony CX 520 VE
Hardware:   Acer NG-A717-72G-71YD, Win 11 , i7-8750 H, 16GB, GTX 1060 6GB, 250GB SSD, 1TB HDD
NLE:  Sony Vegas Pro 13.0 Build 453
            Vegas Pro 14.0 Build 270
            Vegas Pro 21.0 Build 300

 

NickHope wrote on 9/10/2016, 1:27 AM

Thanks guys. That must have snuck in under my radar some time in the last 5 years. I wonder if I can assign it to a keyboard shortcut that is an easier one-handed stretch than Alt+[ and Alt+]... Or maybe I can put it on a couple of my Shuttle Pro buttons. Not at my desk for a couple of days...

Marco. wrote on 9/10/2016, 4:12 AM

Yes, this works regular way (via menu "Options/Customize keybord") . I assigned it to I and O and (Loop-Region marker to Ctrl+I and Ctrl+O instead) because to me while editing this is the most often used feature at all.

NickHope wrote on 9/12/2016, 11:15 AM

Thanks Marco, but actually I found it quite frustrating using these commands, because they don't work on the event under the cursor if another event on the timeline is selected. In my workflow another event often is selected because it was trimmed in another way, such as dragging the ends. I'm lazy and don't want to make the extra click to select the event under the cursor before trimming. So I wrote a pair of scripts that deselects all the events on the timeline before running the Trim commands, and I prefer how it works now. Thanks to John Rofano for this old script that guided my way with the shell & SendKeys. I also assigned I and O keyboard shortcuts to these scripts like Marco.

DeleteFromEventStartToCursor.js

// DeleteFromEventStartToCursor.js by Nick Hope
//
// This script deselects all the events on the timeline then runs the "Trim Start" command, which
// does not work on the event under the cursor if another event on the timeline is selected.
//
// Thanks to John Rofano for the Shell/SendKeys code from a previous script.
//
// Last updated 12th Sept 2016

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

try
{
	// Cycle through all tracks and deselect all events
	var count : int = 0;
	for (var track in Vegas.Project.Tracks)
	{
		for (var trackEvent in track.Events)
		{
			trackEvent.Selected= false;
			count++;
		}
	}
	
	// Use SendKeys in a Windows shell as the VEGAS API does not yet give access to Trim.Start
	var wshShell = new ActiveXObject("WScript.Shell");
	wshShell.SendKeys("%{[}"); // Trim Start ( ALT+[ )
}

catch(e)
{
	MessageBox.Show(e.Message, "Unexpected Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}

DeleteFromCursorToEventEnd.js

// DeleteFromCursorToEventEnd.js by Nick Hope
//
// This script deselects all the events on the timeline then runs the "Trim End" command, which
// does not work on the event under the cursor if another event on the timeline is selected.
//
// Thanks to John Rofano for the Shell/SendKeys code from a previous script.
//
// Last updated 12th Sept 2016

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

try
{
	// Cycle through all tracks and deselect all events
	var count : int = 0;
	for (var track in Vegas.Project.Tracks)
	{
		for (var trackEvent in track.Events)
		{
			trackEvent.Selected= false;
			count++;
		}
	}
	
	// Use SendKeys in a Windows shell as the VEGAS API does not yet give access to Trim.End
	var wshShell = new ActiveXObject("WScript.Shell");
	wshShell.SendKeys("%{]}"); // Trim End ( ALT+] )
}

catch(e)
{
	MessageBox.Show(e.Message, "Unexpected Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}

P.s. Before I wrote those new scripts I did some work with John Meyer's script in the previous post and noticed that my original question was already answered by John in the script. I removed this line as instructed and the cursor stayed put:

Vegas.Cursor = EventBegin; // Remove this line to keep cursor in same location.

 

Marco. wrote on 9/12/2016, 11:30 AM

This is what SEMW extension (see link mentioned above) does, too.

So the good point is, Vegas Pro often offers many ways to go. ;)

NickHope wrote on 9/12/2016, 12:26 PM

This is what SEMW extension (see link mentioned above) does, too.

But it doesn't ripple, even if Auto Ripple is on. And CTRL+F (post-edit ripple) doesn't work either 🙁

(p.s. But thanks for reminding me about the Split command in SeMW Extensions, which I think behaves slightly better than the script I posted today in another thread)

Edit: I presented my refined ALT+[ and ALT+] workflow in this thread.