Can I copy over image keyframes when duplicating image onto new track?

TAGyerit wrote on 11/13/2024, 1:20 PM

Is it possible using Vegas Pro scripts to highlight an image (that contains keyframes) on a track, run the script and create a new track above the original track and copy the image onto the new track and have the existing keyframes included in the new image as well?

It's a simple matter of course to just right-click an existing track and select "Duplicate Track", which creates a new track under the original and retains keyframes in an image, but then I have to move that duplicate track up above the original, and then give it a name. I have to do it many many times, and then run an existing script I have on the new track image. I'd love to be able to combine "duplicate track" in some way into the existing script I'm applying afterwards.

Here's the basic script I tried to create but it doesn't include keyframes, and I'm not having luck having the script actually access the "Duplicate Track" function that exists in Vegas Pro.

I can deal with it if this isn't doable, but if it is and someone can steer me in the right direction it'd be greatly appreciated. Here's the script that does not copy keyframes:
 

using System;
using ScriptPortal.Vegas;

public class EntryPoint
{
    public void FromVegas(Vegas vegas)
    {
        // Find the highlighted video event and its track
        Track originalTrack = null;
        VideoEvent highlightedEvent = null;

        foreach (Track track in vegas.Project.Tracks)
        {
            foreach (TrackEvent evt in track.Events)
            {
                if (evt.Selected && evt is VideoEvent)
                {
                    highlightedEvent = (VideoEvent)evt;
                    originalTrack = track;
                    break;
                }
            }
            if (highlightedEvent != null)
                break;
        }

        // Check if a highlighted video event was found
        if (highlightedEvent == null || originalTrack == null)
        {
            Console.WriteLine("No highlighted video event found.");
            return;
        }

        // Create a new track directly above the original track
        Track newTrack = new VideoTrack(originalTrack.Index, "New Duplicate w Keyframes");
        vegas.Project.Tracks.Add(newTrack);
        Console.WriteLine("New track 'New Duplicate w Keyframes' created above the original track.");

        // Copy the highlighted event to the new track
        VideoEvent duplicateEvent = new VideoEvent(highlightedEvent.Start, highlightedEvent.Length);
        newTrack.Events.Add(duplicateEvent);
        duplicateEvent.AddTake(highlightedEvent.Takes[0].MediaStream);
        Console.WriteLine("Highlighted image copied to the new 'New Duplicate w Keyframes' track.");
    }
}

Thanks in advance. :-)

Comments

jetdv wrote on 11/13/2024, 3:00 PM

What, exactly, are you wanting to copy?

You can COPY the event to the new track and it should include all effects & Pan/Crop settings:

evnt.Copy(newTrack, StartTime);

Or are you referring to Track Motion settings?

jetdv wrote on 11/13/2024, 3:03 PM

In other words, instead of:

        // Copy the highlighted event to the new track
        VideoEvent duplicateEvent = new VideoEvent(highlightedEvent.Start, highlightedEvent.Length);
        newTrack.Events.Add(duplicateEvent);
        duplicateEvent.AddTake(highlightedEvent.Takes[0].MediaStream);
        Console.WriteLine("Highlighted image copied to the new 'New Duplicate w Keyframes' track.");

You might try:

        // Copy the highlighted event to the new track
        highlightedEvent.Copy(newTrack, highlightedEvent.Start);
        Console.WriteLine("Highlighted image copied to the new 'New Duplicate w Keyframes' track.");

 

TAGyerit wrote on 11/13/2024, 3:11 PM

Woohoo! Yep, that's all I needed, using evnt.Copy(newTrack, StartTime); worked right out of the box, thank you!!!!