Use Vegas Scripting to add media file to a specific track

andycam wrote on 5/21/2019, 4:45 PM


I'm using Vegas Pro 15 (Build 416) and C# for scripting. I'm trying to add a new media file (mp4 with video and audio track) to a specific video track. The media files are not added to the correct tracks, and I don't understand why. Can anyone advise please?

This is my code:

            VideoTrack TrackVideoClip = vegas.Project.AddVideoTrack();
            TrackVideoClip.Name = "Clips (Video)";
            VideoTrack TrackOverlay1 = vegas.Project.AddVideoTrack();
            TrackOverlay1.Name = "Overlay1";
            AudioTrack TrackVideoClipAudio = vegas.Project.AddAudioTrack();
            TrackVideoClipAudio.Name = "Clips (Audio)"; 

            foreach (Track track in vegas.Project.Tracks)
                    track.Selected = false;
                TrackVideoClip.Selected = true;
                TrackVideoClipAudio.Selected = true;


The tracks are getting selected, but the media is landing in the wrong track "Overlay1" and an additional audio track gets added by the import. Screenshot of the result:





Luka wrote on 5/22/2019, 1:41 PM

try it with this example from the official Vegas Pro Scripting FAQ:

andycam wrote on 5/22/2019, 4:44 PM

I'm trying the other way to add media, which is mentioned in the Scripting FAQ aswell. I would like to avoid the hassle of creating VideoEvent objects. From the description in the FAQ it looks like it should work with specific tracks aswell.

andycam wrote on 5/23/2019, 3:53 PM

Apparently this bug I'm experiencing existed for a long time. Two users were already talking about this issue in 2008 (11 years ago!):

They didn't really have a fix. Probably easier to work with Events. I'll try that.