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);
}
}
}