Adding Solid Black Color to Vegas Pro script help

andy-0 wrote on 12/11/2024, 3:42 PM

I'm trying to write a script that adds a solid black color to Vegas Pro, but I don't know how to apply the function so that the solid color is black instead of white. Could someone help me?

using System;
using System.Windows.Forms;  // Namespace required for MessageBox
using ScriptPortal.Vegas;

namespace Test_Script
{
    public class EntryPoint
    {
        public void FromVegas(Vegas vegas)
        {
            // Get the first track of the project
            Track Mtrack = vegas.Project.Tracks[0];
            string genUID = "{Svfx:com.vegascreativesoftware:solidcolor}";  // UID of the Solid Color plugin
            PlugInNode plugin = vegas.Generators.GetChildByUniqueID(genUID);

            // Check if the plugin was found
            if (plugin == null)
            {
                MessageBox.Show("The solid color generator was not found.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            // Creating media from the plugin
            Media media = new Media(plugin);
            MediaStream stream = media.Streams.GetItemByMediaType(MediaType.Video, 0);

            // Creating a video event with a duration of 15 seconds
            VideoEvent newEvent = new VideoEvent(vegas.Transport.CursorPosition, Timecode.FromSeconds(15));
            Mtrack.Events.Add(newEvent);

            // Creating the Take for the event with the media stream from the Solid Color plugin
            Take take = new Take(stream);
            newEvent.Takes.Add(take);
        }
    }
}
 

Comments

Thiago_Sase wrote on 12/11/2024, 4:58 PM

@andy-0 Hello, this script may help you;

using System;
using ScriptPortal.Vegas;

namespace Test_Script
{
    public class Class1
    {
        public Vegas myVegas;
        public void Main(Vegas vegas)
        {
            myVegas = vegas;

            Track myTrack = null;

            foreach (Track track in myVegas.Project.Tracks)
            {
                if (track.Selected)
                {
                    myTrack = track;
                    break;
                }
            }

            if (myTrack == null)
            {
                return;
            }

            string genUID = "{Svfx:com.vegascreativesoftware:solidcolor}";
            int presetCount = 1;
            PlugInNode plugIn = null;
            plugIn = myVegas.Generators.GetChildByUniqueID(genUID);

            Media media = new Media(plugIn);
            MediaStream stream = media.Streams.GetItemByMediaType(MediaType.Video, 0);

            VideoEvent newEvent = new VideoEvent(myVegas.Transport.CursorPosition, Timecode.FromSeconds(15));
            myTrack.Events.Add(newEvent);
            Take take = new Take(stream);
            newEvent.Takes.Add(take);

            if (newEvent.ActiveTake.Media.IsGenerated())
            {
                newEvent.ActiveTake.Media.Length = Timecode.FromSeconds(120);
            }

            Effect gEffect = newEvent.ActiveTake.Media.Generator;
            gEffect.Preset = gEffect.Presets[presetCount].Name;
        }
    }

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

 

Last changed by Thiago_Sase on 12/11/2024, 5:16 PM, changed a total of 4 times.

OS: Windows 10 22H2
CPU: Intel Core I7 12700
MEMORY: 32GB DDR4 3200MHz
GHAPHIC CARD: RTX 3060 8GB
HARD DRIVES: SSD for System and M.2 for Media Files

jetdv wrote on 12/12/2024, 9:55 AM

From what Thiago_Sase posted above, this is the important part - you have to pick the right preset.

            Effect gEffect = newEvent.ActiveTake.Media.Generator;
            gEffect.Preset = gEffect.Presets[presetCount].Name;

If you notice, int presetCount = 1; was defined above and the "black" preset is number 1 (white is zero, red is 2, green is 3 etc...) It's best to use the number as the "name" of the preset can change based on the language being used.