Script to select clips skipping one clip after another

debojitacharjee wrote on 12/20/2023, 1:00 AM

I need a script that could select all the clips on the timeline of Vegas Pro but it should skip every clip next to the selected one (alternatively). For example, if there are 3 clips on the timeline, then the script should select the 1st and 3rd clip but should not select the 2nd clip.

Please let me know how I can change the selecting pattern of the script also (if possible).

Comments

jetdv wrote on 12/20/2023, 8:47 AM

@debojitacharjee This will select every other event on all tracks and allow other options such as every 3rd, 4th, 5th... even "all":

using ScriptPortal.Vegas;

namespace Test_Script
{
    public class Class1
    {
        public Vegas myVegas;

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

            int SelectCount = 2; //2 = every other, 3 = every third, 4 = every 4th...

            foreach(Track myTrack in myVegas.Project.Tracks)
            {
                int currentCount = 1;
                foreach(TrackEvent evnt in myTrack.Events)
                {
                    evnt.Selected = false;
                    if (currentCount == 1)
                    {
                        evnt.Selected = true;
                    }
                    currentCount++;

                    if (currentCount > SelectCount)
                    {
                        currentCount = 1;
                    }
                }
            }
        }
    }
}

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

This line determines which ones to pick:

int SelectCount = 2; 

With a 2, it will select every other event. Change it to 3 and it will select every 3rd event. Change it to 4 and it will select every 4th event. Change it to 1 and it will select EVERY event.

This line will actually determine which event to start with:

int currentCount = 1; 

Set to 1, it will start with the first event and then skip the number determined by "SelectCount". However, if you wanted to select 2, 4, 6, 8... instead, you could change currentCount to start at "2" instead.

If you didn't want other patterns and only wanted every other event, a boolean flag could also be used which would simplify the code:

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)
            {
                bool SelectThisOne = true;
                foreach (TrackEvent evnt in myTrack.Events)
                {
                    evnt.Selected = SelectThisOne;
                    SelectThisOne = !SelectThisOne;
                }
            }
        }
    }
}

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

In this case we set a boolean flag to true so the first one is selected and then we change the boolean flag to the opposite (i.e. not true or false). The next one will be not selected and we change the boolean flag to "not false" or true. Therefore it will just alternate between true/false all the way down the timeline and is definitely shorter (two lines of code versus 11) but will only do every other event and not other combinations like every 3rd, 4th, 5th...

jetdv wrote on 12/20/2023, 1:56 PM

Also, a full tutorial on this will be available on my YouTube channel the last Monday in January.