Adding plugin to MediaFX rather than EventFX from selected tracks

Santamaria wrote on 7/8/2020, 3:14 AM

What I'm trying to do is to be able to select the clips from track view (rather than mediapool) and add a plugin to MediaFX (like you do with VEGAS Video Stabilizer) instead of EventFX but I just can't figure out how to do this. My base code is something I found on this forum and it works great for just adding it as a EventFX but how can I modify it to put the effect as MediaFX instead?

I'm having a brain freeze right now, can anyone help me?

            foreach (Track track in vegas.Project.Tracks)
            {
                if (!track.IsVideo()) continue;

                foreach (VideoEvent videoEvent in track.Events)
                {

                    if (videoEvent.Selected)

                    {

                        Effect effect = new Effect(plugIn);

                        videoEvent.Effects.Add(effect);

                        effect.Preset = presetName;

                    }

                }
            }

 

Comments

jetdv wrote on 7/8/2020, 9:20 AM

Your code is only looking at video events on the timeline. videoEvent.Effects.Add(effect); is adding the effect to that event. You will need to dig down to the underlying media to add it as a media effect. Perhaps something liek this:

Media media = Vegas.Project.MediaPool.Find(trackEvent.ActiveTake.MediaPath);

Santamaria wrote on 7/8/2020, 11:33 AM

Your code is only looking at video events on the timeline. videoEvent.Effects.Add(effect); is adding the effect to that event. You will need to dig down to the underlying media to add it as a media effect. Perhaps something liek this:

Media media = Vegas.Project.MediaPool.Find(trackEvent.ActiveTake.MediaPath);

That did it, thanks for the help!

Santamaria wrote on 7/8/2020, 11:34 AM

Here's the final code if anyone ever finds a need for it:

 

/**
 * Add plugin (stabilizer) to selected clips from track view 
 *
 **/
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Windows.Forms;
using ScriptPortal.Vegas;

public class EntryPoint
{
    Vegas myVegas;

    public void FromVegas(Vegas vegas)
    {
        myVegas = vegas;
        
        // Change the pluginName below to the FX you want to apply
        string pluginName = "VEGAS Video Stabilization";

        // Change the presetName below to the preset you want to apply
        string presetName = "pro";
    
        try
        {
            PlugInNode plugIn = vegas.VideoFX.GetChildByName(pluginName);
            
            // Add plugin to selected clips from track view
            foreach (Track track in vegas.Project.Tracks)
            {
                if (!track.IsVideo()) continue;
                
                foreach (VideoEvent videoEvent in track.Events)
                {
                    if (videoEvent.Selected)
                    {
                        Media media = vegas.Project.MediaPool.Find(videoEvent.ActiveTake.MediaPath);

                        // Skip if it already have the effect
                        if (MediaHasEffect(media, plugIn))
                            continue;
                
                        Effect effect = new Effect(plugIn);
                        media.Effects.Add(effect);
                        effect.Preset = presetName;
                    }
                }
            }

        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
        }
    }
    
    public bool MediaHasEffect(Media media, PlugInNode plugIn)
    {
        foreach (Effect effect in media.Effects)
        {
            if (effect.PlugIn == plugIn)
                return true;
        }
        return false;
    }
}