Comments

jetdv wrote on 8/22/2023, 1:20 PM

See if this gets you going on the right track... It will move all selected events to the "next track down". Of course, you'll need to modify this to suit your needs plus, it "assumes" there is a track below it where the new event can be placed - in other words, it doesn't check to see if it "can't" work.

Also, to do this you set the event track to the new track. Please see my tutorials to see whey we are counting backwards through the events and the pitfalls of just removing events from a track:

using System;
using System.Collections.Generic;
using System.Collections;
using System.IO;
using System.Text;
using System.Windows.Forms;
using System.Globalization;
using System.Drawing;
using System.Runtime;
using System.Xml;
using ScriptPortal.Vegas;

namespace Test_Script
{
    public class Class1
    {
        public Vegas myVegas;

        public void Main(Vegas vegas)
        {
            myVegas = vegas;

            foreach (Track myTrack in myVegas.Project.Tracks)
            {
                if (myTrack.IsVideo())
                {
                    for (int i=myTrack.Events.Count - 1; i>=0; i--)
                    {
                        TrackEvent evnt = myTrack.Events[i];
                        if (evnt.Selected)
                        {
                            evnt.Track = myVegas.Project.Tracks[evnt.Track.Index + 1];
                            evnt.Selected = false;
                        }
                    }
                }
            }
        }
    }
}

public class EntryPoint
{
    public void FromVegas(Vegas vegas)
    {
        Test_Script.Class1 test = new Test_Script.Class1();
        test.Main(vegas);
    }
}

 

This is the main part:

                            evnt.Track = myVegas.Project.Tracks[evnt.Track.Index + 1];
                            evnt.Selected = false;

In this case, we simply set the track to the destination track (which is the "next" track) and the start time remains the same so it will go straight down. Then, because I'm doing every selected event, that moved event is still selected so I deselect it.

Terrance wrote on 8/22/2023, 1:45 PM

What would I do without you Jetdv? Just what I needed. One minor follow-up question - could I use a track's name to determine the destination. Is there a method such as myTrack = myVegasProject.Tracks.Name("Label")?

jetdv wrote on 8/22/2023, 3:21 PM

You would need to loop through the tracks to find the one named "Label". Then use that as your destination track.

Track destTrack = null;
foreach(Track myTrack in myVegas.Project.Tracks)
{
    if (myTrack.Name == "Label")
    {
        destTrack = myTrack;
    }
}

Then you could set evnt.Track = destTrack - just make sure it's not still "null"!