Detecting and inserting gaps - basic operations

gary-o wrote on 7/24/2020, 10:05 AM

Beginner scripting questions:

1. how would I write code that detects a gap in the timeline of, say, more than 1 second?

2. how would I instruct Vegas to Insert Time (for, say, 3 seconds) at the current cursor?

I tried this but it crashed:

using ScriptPortal.Vegas;
namespace InsertGap
(    public class EntryPoint
    {
        public void FromVegas(Vegas vegas)
        {
         InsertTime (vegas.TransportControl.CursorPosition, "00:00:03:00");
        }
    }

What bits am I missing? 😳

These are the errors I'm getting so far:

The name 'InsertTime' does not exist in the current context
'ScriptPortal.Vegas.Vegas' does not contain a definition for 'TransportControl'

2a. in general, how do I execute a menu, key or mouse command - such as Insert Empty Event, Import Media File, Insert Media (at a specific timecode and track), or move the cursor to the next/previous marker/region/event?

It seems to me to be a matter of reading the properties or executing the methods for the various API functions.

But there's other "housekeeping" matters that I can't find any info about (e.g. do I need any extra special "using" or "import" statements?

Thanks for tips, suggestions, instructions... :)

Comments

jetdv wrote on 7/24/2020, 10:47 AM

1. You cannot see "gaps". But you can determine if there is one. Say you have event1 and event2 on the timeline. If event2.start - (event1.start + event1.length) > 1 second, then you would have a larger than 1 second gap between them. So you have to look basically at where event1 ends and where event2 begins to determine what gap may be there.

2. You're using the command incorrectly. Try:

vegas.Project.InsertTime(vegas.Transport.CursorPosition, "00:00:30:00");

2a. You have to manually add the event to the timeline. You have to add the event to the timeline, add the media to a Take, and then add the Take to the event. (Not adding the media or Take would be an empty event) Here's an example code segment:

VideoEvent AddVideoEvent(Vegas vegas, String mediaFile, Timecode start, Timecode length) 
{
    Media media = new Media(mediaFile);
    VideoTrack track = vegas.Project.AddVideoTrack();
    VideoEvent videoEvent = track.AddVideoEvent(start, length);
    Take take = videoEvent.AddTake(media.GetVideoStreamByIndex(0));
    return videoEvent; 
}
gary-o wrote on 7/24/2020, 11:46 AM

Thanks. I'll work on your suggestions for point 1.

For point 2, I'm still getting an error:

vegas.Project.InsertTime(vegas.Transport.CursorPosition, "00:00:03:00");
or
vegas.Project.InsertTime(vegas.Transport.CursorPosition, 3000);

Argument 2: cannot convert from 'string' (or 'int') to 'ScriptPortal.Vegas.Timecode'

2a It's these little details that I'm finding very difficult to find info about with Vegas scripting. So to execute a command within in the editor, one simply calls the class/object using the full class (path) name, right?

e.g. Vegas.Project.VideoBusTrack.VideoColor (r,g,b);

(How does one know whether to use three red-green-blue values or four red-green-blue-alpha values, or a single combined color value...? And what is the syntax for setting the color vs reading the current color? And how does one specify which track?)

Still very much beginner script-writing questions... :o

jetdv wrote on 7/24/2020, 5:03 PM

Sorry, I was really just using your formatting. Try this:

vegas.Project.InsertTime(vegas.Transport.CursorPosition, Timecode.FromString("00:00:03:00")); 
or 
vegas.Project.InsertTime(vegas.Transport.CursorPosition, new Timecode("00:00:03:00"));

 

2a. "Vegas.Project.VideoBusTrack" is not valid. There is no "VideoBusTrack" to access under "Project". There is a "VideoBus" but no "VideoBusTrack". And there is no "VideoColor" under "VideoBus". We're happy to help you but it might help to have a little background on what you're trying to do instead of just throwing out one line of code.

Please go here: https://www.vegascreativesoftware.com/us/downloads/#c24726

Download both the API and the FAQ for scripting. The code I gave you above came straight from the FAQ.