Scripts for a fellow Vegas user

ram17 wrote on 7/23/2019, 8:54 PM

I have a friend who uses Vegas & wanted to help him modify these 2 scripts he can use for now, until he can buy VP 17 this December & also Vegasaur which I am using & recommended to him.

1.The first script is to delete spaces between selected events but this script does not include the audio in the video that is selected. So maybe if its possible to include the audio also if its highlighted.

2. It's the opposite of the script select all the events at the right of the cursor which is select all events at the left of the cursor.

Thank you & CTTO of this scripts.

/** 
* Program: 
* Description: Remove gaps between events. This removes gaps in SELECTED events only. The remove gap function only works on selected events. 
               All events before and after the selected event are NOT processed. The GAP constant is used as the defined spacer between events
               as they are processed. If you want the space between events to be 0, then set GAP to 0. GAP unit is milliseconds. Default is 1000 (1sec).
               This script was created because the only other RemoveGaps script found on the interet had a bug where it truncated the end of each event
               on complex tracks. This script works on complex tracks with 1000's of events. Also the other script processed all events on a track, this
               script processes only selected tracks, so you can selectivly decide which evemts to process and which to not process.
* Author: JRD
* 
* Date: April 17, 2011
**/ 

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


try
{
    Debug.WriteLine("RemoveGaps-> START");
    
    var GAP = 0;

    // step through all selected video events:
    var FirstTrack : Track = Vegas.Project.Tracks.Item(0);
    var idx = 0;
    var countSel = 0;
    // step through all selected video events:
    for (var track in Vegas.Project.Tracks) 
    {
        if( !track.Selected || track.MediaType == MediaType.Audio) continue;
        
        var tracktime = new Timecode(0);
        var last = 0;
        var begin = 0;
        for (var evnt in track.Events) 
        {
            if (evnt.Selected)
            {
                // start after first event
                if (idx > 0 && countSel > 0)
                {
                    Debug.WriteLine("RemoveGaps-> idx -> " + idx);
                    // get diff between previous this event and last
                    var diff = (evnt.Start.ToMilliseconds() - last); 
                    Debug.WriteLine("RemoveGaps-> diff -> " + diff);
                    //  if diff is greater than GAP? then fill it
                    if (diff > GAP)
                    {
                        var start = Timecode.FromMilliseconds(last + GAP);
                        var end =  Timecode.FromMilliseconds(start.ToMilliseconds() + evnt.Length.ToMilliseconds());
                        var len =  Timecode.FromMilliseconds( evnt.End.ToMilliseconds() - evnt.Start.ToMilliseconds());
                        
                        Debug.WriteLine("RemoveGaps-> diff > GAP " );
                        Debug.WriteLine("RemoveGaps-> diff > Set evnt.Start to-> " + start.ToMilliseconds().ToString());
                        Debug.WriteLine("RemoveGaps-> diff > Set evnt.End to-> " + end.ToMilliseconds().ToString());
                        Debug.WriteLine("RemoveGaps-> diff > Set evnt.Length to-> " +len.ToMilliseconds().ToString());
                        
                        evnt.Start = start; // new start
                        evnt.End = end; // new end
                        evnt.Length = len; // calculate exact length
                        countSel++;
                    }
                }
                countSel++;
            }
            last = evnt.End.ToMilliseconds();
            tracktime = tracktime + evnt.Length;
            idx++;
        }
    }
    Debug.WriteLine("RemoveGaps-> DONE");
}

catch (errorMsg)
{
    Debug.WriteLine("RemoveGaps-> ERROR-> " + errorMsg);
    MessageBox.Show(errorMsg, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
/** 
 * Program: SelectEventsFromCursor.js
 * Description: This script will select all the events on all tracks that are 
 *              under the cursor position and to the right of it.
 * Author: Johnny (Roy) Rofrano  john_rofrano at hotmail dot com
 * 
 * Date: March 24, 2004 
 *
 **/ 

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

try
{
    // step through all the tracks
    for (var track in Vegas.Project.Tracks) 
    {
        // Step through all events
        for (var evnt in track.Events) 
        {
            // Check to see if event is under or to the right of the cursor
            if (-1 == Vegas.Cursor.CompareTo(evnt.Start + evnt.Length))
            {
                evnt.Selected = true;
            }
        }
    }
}
catch (errorMsg)
{
    MessageBox.Show(errorMsg, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}

 

Comments

Marco. wrote on 7/24/2019, 2:06 AM

You missed to tell which Vegas version your friend uses. Closing gaps for both video and audio is a core function of the current versions of Vegas Pro which then would not need a script.

For the second one – selecting Events left from cursor – and for the Magix versions of Vegas Pro this JS script works fine for me:

import ScriptPortal.Vegas; 
import System.Windows.Forms;

try
{
    for (var track in Vegas.Project.Tracks) 
    {
        for (var evnt in track.Events) 
        {
            if (1 == Vegas.Cursor.CompareTo(evnt.End - evnt.Length))
            {
                evnt.Selected = true;
            }
        }
    }
}
catch (errorMsg)
{
    MessageBox.Show(errorMsg, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}

 

ram17 wrote on 7/24/2019, 6:22 AM

Thanks @Marco.​​​​​​

He is currently using VP 14. Which I doubt have the close gaps function.

vkmast wrote on 7/24/2019, 6:47 AM

Note also @JohnnyRoy here and "Close Gaps" in the screenshot.

ram17 wrote on 7/24/2019, 8:07 AM

Thanks @vkmast​​​​​​.. You mean the VASST apps? I think my friend will rely on a free script just for now. I tried other close gaps scripts I have found, but all of them just moved the video not including their own audio.

vkmast wrote on 7/24/2019, 8:17 AM

@ram17 Yes, Event Tools is one the VASST FasstApps.

ram17 wrote on 7/24/2019, 8:29 AM

Yup, thanks for pointing that out, I'll try to introduce that to him. But he planned to purchase Vegasaur along with Vegas 17, I think its a redundant function of scripts to have both.

Marco. wrote on 7/24/2019, 8:53 AM

I found a free script which would close the gaps of all Events of selected tracks. Not sure if this would help.

wwaag wrote on 7/24/2019, 10:06 AM

This also works which I just posted on another thread.

If you want to just remove gaps, keep head and tail frames set to 0, select the tracks and tick Auto-Ripple. You can download it for free here. https://tools4vegas.com/trim-frames/

ram17 wrote on 7/24/2019, 10:21 AM

He specifically needs a script with this function "close gaps with selected events(videos) including their corresponding own audio/s".. It's like the close gaps function in VP16.

I think I should ask him also to become a forum member here, it's not easy to be his spokesperson & requesting favor with fellow Vegas users 😊

wwaag wrote on 7/24/2019, 12:59 PM

Added option to close gaps for selected events only. Same link.

ram17 wrote on 7/24/2019, 6:47 PM

Thank you @wwaag​​​​​​.. Your HOS tools are really good.