How to select a track using script?

debojitacharjee wrote on 12/30/2023, 3:15 AM

I am using the following script to select events on the timeline but this script selects all the tracks on the timeline. I need to modify the script so that I would only select the events of the selected track only.

SCRIPT:

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 = 2; // This line will actually determine which event to start with
                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);
    }
}
 

Please tell me how I can do that.

Comments

Jack S wrote on 12/30/2023, 5:00 AM

@debojitacharjee

After the statement

    foreach(Track myTrack in myVegas.Project.Tracks)
    {

you need to add a test to see if the track is selected.

if (myTrack.Selected)                               //If the current track is selected
{

then include the rest of your code.

 

Last changed by Jack S on 12/30/2023, 5:01 AM, changed a total of 1 times.

My system
Genshin Infinity Gaming PC
Motherboard Gigabyte H610M H: m-ATX w/, USB 3.2, 1 x M.2
Power Supply Corsair RM750X
Intel Core i7-13700K - 16-Core [8P @ 3.4GHz-5.4GHz / 8E @ 2.50GHz-4.20GHz]
30MB Cache + UHD Graphics, Ultimate OC Compatible
Case Fan 4 x CyberPowerPC Hyperloop 120mm ARGB & PWM Fan Kit
CPU Fan CyberPowerPC Master Liquid LITE 360 ARGB AIO Liquid Cooler, Ultimate OC Compatible
Memory 32GB (2 x 16GB) DDR5/5200MHz Corsair Vengeance RGB
MSI GeForce RTX 4060 Ti 8GB - Ray Tracing Technology, DX12, VR Ready, HDMI, DP
System drive 1TB WD Black SN770 M.2 NVMe PCIe SSD - 5150MB/s Read & 4900MB/s Write
Storage 2 x 2TB Seagate BarraCuda SATA-III 6.0Gb/s 7200RPM
Windows 11 Home (x64)
Monitors
Generic Monitor (PHL 222V8) connected to GeForce RTX 4060 Ti
Generic Monitor (SAMSUNG) connected to iGPU

Camcorder
SONY Handycam HDR-XR550VE

jetdv wrote on 12/30/2023, 6:43 AM
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)
            {
                if (myTrack.Selected)
                {

                    int currentCount = 2; // This line will actually determine which event to start with
                    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);
    }
}

 

debojitacharjee wrote on 1/2/2024, 1:46 AM
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)
            {
                if (myTrack.Selected)
                {

                    int currentCount = 2; // This line will actually determine which event to start with
                    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);
    }
}

 

So which IDE or code editor can be used for scripting of VP? Where do I get the library files for C#?

jetdv wrote on 1/2/2024, 9:50 AM

@debojitacharjee The above code can actually be done in Notepad. But you probably want something a little move sophisticated than that. Some people use VSCode. I prefer Visual Studio (and actually prefer 2015). With Visual Studio I get code completion by typing "." it tells me what options are available. Have you looked at my tutorials? Let's go back to the very beginning to the second video I posted:

You might want to look at the third one too:

The answer to your above question is also in these tutorials.

debojitacharjee wrote on 1/5/2024, 6:52 AM

@debojitacharjee The above code can actually be done in Notepad. But you probably want something a little move sophisticated than that. Some people use VSCode. I prefer Visual Studio (and actually prefer 2015). With Visual Studio I get code completion by typing "." it tells me what options are available. Have you looked at my tutorials? Let's go back to the very beginning to the second video I posted:

You might want to look at the third one too:

The answer to your above question is also in these tutorials.

Your tutorials are good but I need to know about the syntax and the keywords supported by Vegas. This has something to do with the library files. Is there any documentation available for reference?

jetdv wrote on 1/5/2024, 7:58 AM

VEGAS API and FAQ download link: https://www.vegascreativesoftware.com/us/downloads/#c24726

everything else is C# which you can google for the syntax.

If you use Visual Studio as your editor, you can have code completion as well which also helps.