[Absolute beginner] Unexpected and inconsistent behaviour in my script

SUPERNOOB20 wrote on 12/28/2025, 1:31 PM

Hi! I have been trying to get into Vegas Scripting, but my scripts either don't compile; throw various nonsense errors; or sometimes do compile, but show nonsensical behaviour

 

Consider for example the following code (Which I stored in "C:\Program Files\VEGAS\VEGAS Pro 17.0\Script Menu\hello_fruits_vegas.cs")

using System.Windows.Forms;

using ScriptPortal.Vegas;


public class EntryPoint

{

    public void FromVegas(Vegas vegas)

    {


        string[] fruits;

        fruits = new string[] {"banana", "apple", "tomato", "cat (just kidding)"};

       

        foreach (Track myTrack in vegas.Project.Tracks)

        {

            foreach (TrackEvent event in myTrack.TrackEvents)

            {

                if (event.Selected)

                {

                    MessageBox.Show(fruits[1]);

                }

            }

        }

    }

}

 

This code will either show message boxes of all the fruits in fruits (unexpected behaviour) or not compile at all and show an error similar to this one (taking from a slightly different script because I failed to reproduce):

This is the code for that one, if you were wondering:

using System;

using System.Drawing;

using System.Collections;

using System.Windows.Forms;

using ScriptPortal.Vegas;



public class EntryPoint

{

    public void FromVegas(Vegas vegas)

    {

       

        foreach (Track myTrack in vegas.Project.Tracks)

        {

            foreach (VideoEvent event in myTrack.Events)

            {

                if (event.Selected)

                {

                    event.MaintainAspectRatio = false;       // videoEvent.MaintainAspectRatio;

                }

            }

        }

               


        MessageBox.Show("Meow :3");

    }

}

 

As you can see, the code is totally fine and it should compile just fine... what on Earth is going on? "^^

 

~ SUPERNOOB

 

Comments

SUPERNOOB20 wrote on 12/28/2025, 2:03 PM

** Update on the second code snippet:


 

using System;

using System.Drawing;

using System.Collections;

using System.Windows.Forms;

using ScriptPortal.Vegas;



public class EntryPoint

{

    public void FromVegas(Vegas vegas)

    {

       

        foreach (Track myTrack in vegas.Project.Tracks)

        {

            foreach (TrackEvent event in myTrack.Events)

            {

                if (event.Selected) && (event.MediaType.Video)

                {

                    event.MaintainAspectRatio = false;       // videoEvent.MaintainAspectRatio;

                }

            }

        }

               


        MessageBox.Show("Meow :3");

    }

}

(It still doesn't work anyway)

zzzzzz9125 wrote on 12/28/2025, 8:46 PM

@SUPERNOOB20 You've made a total of two mistakes:

  1. In C#, "event" is reserved as a keyword, so you can't use it as a variable name. I usually use "ev" instead.
  2. It should not be "myTrack.TrackEvents", but "myTrack.Events". For more details, see the Script API: https://help.magix-hub.com/video/vegas/23/en/content/topics/external/scriptapi.htm
SUPERNOOB20 wrote on 12/28/2025, 8:49 PM

Good news! It works now. Problem solved :)

Admittedly, I had to take the code from https://www.vegascreativesoftware.info/us/forum/vegas-pro-scripts-collections-share-your-script-here--145667/#ca918826 (thank you so much, Gid!!! ^-^)

 

This is how it ended up looking:

using ScriptPortal.Vegas;
using System;
using System.Collections.Generic;
using System.Windows.Forms;public class EntryPoint
{
    public void FromVegas(Vegas myVegas)
    {
        foreach (Track myTrack in myVegas.Project.Tracks)
        {
            if (myTrack.IsVideo())
            {
                foreach (VideoEvent myVideoEvent in myTrack.Events)
                {
                    if (myVideoEvent.Selected)
                    {
                        myVideoEvent.MaintainAspectRatio = false;
                    }
                }
            }
        }
    }
}

 

If you have any doubts please let me know ^_^

SUPERNOOB20 wrote on 12/28/2025, 8:52 PM

@SUPERNOOB20 You've made a total of two mistakes:

  1. In C#, "event" is reserved as a keyword, so you can't use it as a variable name. I usually use "ev" instead.
  2. It should not be "myTrack.TrackEvents", but "myTrack.Events". For more details, see the Script API: https://help.magix-hub.com/video/vegas/23/en/content/topics/external/scriptapi.htm

I see. Both of these things are true. Thank you ^^

Yeah yeah, I've read that Script API over and over again for the last few years. But my IQ is too low and coding is hard for me (@_@)
Thanks for that link though, because I had it in a different format that I was finding harder to follow (the HTML file).

jetdv wrote on 12/29/2025, 9:01 AM

@SUPERNOOB20 make sure you look over my tutorials:

https://www.youtube.com/@JetDVScripts/videos