Script Fails to Apply Specific Effect and Preset in Vegas Pro

andy-0 wrote on 9/16/2024, 12:18 PM

Hi, I need help with a script I'm writing. I'm trying to add a specific effect to it along with a chosen preset, but I'm not having any success getting it to work. Could someone help me figure out what I'm doing wrong, please?

 

using ScriptPortal.Vegas;
using System; // For ArgumentNullException

public class EntryPoint
{
    public void FromVegas(Vegas vegas)
    {
        try
        {
            // Assign the Vegas Pro instance to the local object
            Vegas myVegas = vegas;

            // Check if there are any tracks and events
            if (myVegas.Project.Tracks.Count == 0 || myVegas.Project.Tracks[0].Events.Count == 0)
            {
                throw new InvalidOperationException("No tracks or events found in the project.");
            }

            // Select the first track and the first video event
            Track track = myVegas.Project.Tracks[0];
            VideoEvent videoEvent = (VideoEvent)track.Events[0];

            // Identify the VHS plugin
            string pluginUID = "Svfx:com.redgiantsoftware.Universe_Stylize_VHS_OFX";
            PlugInNode fx = myVegas.VideoFX;
            PlugInNode plugin = fx.GetChildByUniqueID(pluginUID);

            // Check if the plugin was found
            if (plugin == null)
            {
                throw new ArgumentNullException("plugin", "The plugin with the specified UID was not found.");
            }

            // Add the effect to the video event
            Effect effect = new Effect(plugin);
            videoEvent.Effects.Add(effect);

            // Set the effect preset to "vhstelasemfundo"
            string desiredPresetName = "vhstelasemfundo";
            bool presetFound = false;

            // Apply the preset to the effect if available
            foreach (var preset in effect.Presets)
            {
                if (preset.Name.Equals(desiredPresetName, StringComparison.OrdinalIgnoreCase))
                {
                    effect.Preset = desiredPresetName;
                    presetFound = true;
                    Console.WriteLine("Preset applied: " + desiredPresetName);
                    break;
                }
            }

            if (!presetFound)
            {
                // Handle the case where the preset was not found
                Console.WriteLine("The preset '" + desiredPresetName + "' was not found.");
                effect.Preset = effect.Presets.Count > 0 ? effect.Presets[0].Name : null; // Default to the first preset if available
            }
        }
        catch (Exception ex)
        {
            // Log the exception message for debugging
            Console.WriteLine("An error occurred: " + ex.Message);
        }
    }
}


 

Comments

jetdv wrote on 9/16/2024, 12:42 PM

@andy-0, what is happening when you run the script? Are you seeing any messages? Getting a specific error? As I don't have that effect, I can't directly test your script.

andy-0 wrote on 9/16/2024, 1:05 PM

@jetdv practically nothing happens, it seems to be running but it doesn't insert the effects or presets, much less display any error message.

jetdv wrote on 9/16/2024, 1:17 PM

@andy-0 This works for me...

            string plugInUID = "{Svfx:com.vegascreativesoftware:gaussianblur}";
            int presetCount = 3;

            PlugInNode fx = myVegas.VideoFX;
            PlugInNode plugIn = fx.GetChildByUniqueID(plugInUID);

            Effect effect = new Effect(plugIn);
            vEvent.Effects.Add(effect);

            effect.Preset = effect.Presets[presetCount].Name;

I notice you don't have the "{ }" around the effect name. You'll need those brackets added or it won't find the effect. That could be your only issue. So you might try:

string pluginUID = "{Svfx:com.redgiantsoftware.Universe_Stylize_VHS_OFX}";

 

andy-0 wrote on 9/16/2024, 1:22 PM

@andy-0 This works for me...

            string plugInUID = "{Svfx:com.vegascreativesoftware:gaussianblur}";
            int presetCount = 3;

            PlugInNode fx = myVegas.VideoFX;
            PlugInNode plugIn = fx.GetChildByUniqueID(plugInUID);

            Effect effect = new Effect(plugIn);
            vEvent.Effects.Add(effect);

            effect.Preset = effect.Presets[presetCount].Name;

I notice you don't have the "{ }" around the effect name. You'll need those brackets added or it won't find the effect. That could be your only issue. So you might try:

string pluginUID = "{Svfx:com.redgiantsoftware.Universe_Stylize_VHS_OFX}";

 

Thank you very much for your help jetdv I managed to make it work with the changes you recommended thank you very much

zzzzzz9125 wrote on 9/16/2024, 1:25 PM

practically nothing happens, it seems to be running but it doesn't insert the effects or presets, much less display any error message.

@andy-0 Another tip: Use MessageBox.Show() instead of Console.WriteLine() to display the message for the script. Vegas doesn't provide a console.

Using VEGAS Pro 22 build 248 & VEGAS Pro 21 build 208.

Information about my PC:
Brand Name: HP VICTUS Laptop
System: Windows 11.0 (64-bit) 10.00.22631
CPU: 12th Gen Intel(R) Core(TM) i7-12700H
GPU: NVIDIA GeForce RTX 3050 Laptop GPU
GPU Driver: NVIDIA Studio Driver 560.70