📝⚙️(Script) Add Picture-in-Picture to the event.

Comments

jetdv wrote on 3/25/2023, 9:00 AM

@relaxvideo I did not test the code - only reworking what you had already written.

The number in the parentheses tells you which line the error is on. So your first error is on line 28.

It appears line 28 is: OFXEffect ofx = effect.OFXEffect;

So the big question is: Is the effect you're adding an OFX Effect? It appears that answer is yes for "Stereoscopic 3D Adjust".

This:

                OFXEffect ofx = effect.OFXEffect; 

                foreach (OFXParameter parm in ofx.OFXParameters) 
                { 
                    if (parm.ParameterType.ToString() == "PushButton") 
                    { 
                        parm.ParameterChanged(); 
                    } 
                }

should really be (As you should really be verifying it is an OFX Effect before trying to get the OFXEffect variable):
 

            if (effect.PlugIn.IsOFX)

            {
                OFXEffect ofx = effect.OFXEffect;

                foreach (OFXParameter parm in ofx.Parameters)
                {
                    if (parm.ParameterType.ToString() == "PushButton")
                    {
                        parm.ParameterChanged();
                    }
                }
            
}

Now, all my code is written in C# and you're doing .JS so some other changes are needed to make sure everything works. Then, on line 29, .JS does not like the "For Each" loop. Changing to this will eliminate the above errors:
 

import Sony.Vegas;
import System.Windows.Forms;
import Microsoft.Win32;

var plugInName = "Stereoscopic 3D Adjust";
var presetName = "";

try
{
    for (var track in Vegas.Project.Tracks) {
        for (var evnt in track.Events) {
            if (!evnt.Selected || evnt.MediaType != MediaType.Video) continue;

            var fx = Vegas.VideoFX;

            var plugIn = fx.GetChildByName(plugInName);
            if (null == plugIn) {
                throw "could not find a plug-in named: '" + plugInName + "'";
            }

            var effect = new Effect(plugIn);
            evnt.Effects.Add(effect);

            if (null != presetName) {
                effect.Preset = presetName;
            }

            var ofx = effect.OFXEffect;
            for (var parm in ofx.Parameters)
            {
                if (parm.ParameterType.ToString() == "PushButton")
                {   
                    parm.ParameterChanged();
                }
            }
        }
    }
}


catch (errorMsg)

{
MessageBox.Show(errorMsg, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}