Is there a way to create a script that when triggered the selected event is added a video fx? Example: When running the script, the picture in picture plugin is added to the selected event.
Picture In Picture - UID: {Svfx:com.vegascreativesoftware:pictureinpicture}
In short, yes there is a way. The script can add the Picture in Picture effect and can also either pick a preset or adjust the parameters.
The first tutorial gives you information on all of the plugins. The important information for Picture and Picture is listed above. The next tutorial shows how to add an effect to an event. The next one shows how to adjust parameters. The last one shows how to add that effect to an event, track, media, or the entire project.
@jetdv Could you create it and highlight where to choose the plugin and where to change the parameters? To see if I can understand how this script works. Because I don't speak English and I don't understand programming. If it's not a bother, you would do one that adds the picture in picture plugin to the selected event. with scale parameters x and y 1,000
Go back to the script where we were setting the alpha channel. This is the main part:
foreach (Track myTrack in myVegas.Project.Tracks)
{
if (myTrack.IsVideo())
{
foreach (TrackEvent evnt in myTrack.Events)
{
if (evnt.Selected)
{
}
}
}
}
That goes through all of the tracks, confirms it's a video track as we are wanting to add a video effect so we don't need to look at audio tracks, then goes through all of the events on the video track, and looks to see if the event is selected. That's the event(s) to which you want the effect added.
Now, per the second tutorial using the information I listed above which came from the first tutorial, the effect needs to be added to the selected event:
First, we're adding a video effect so we have to work with a video event. So we change the "track event" to a "video event". Then we indicate which effect we want. Look at the effects available in VEGAS, get that specific plugin, get a new effect from that plugin, and add that effect to the event.
Next comes the harder part which is found in the third tutorial. We have to get the OFXEffect but we don't know the "name" of the parameters we want to change so we we'll add this:
This will get us the OFX effect and then list all of the parameters available to us. We're looking for "X" and "Y" to adjust. Now we'll run this and look at all of the messages pop up making note of the ones we want and the types of parameter they are. In this case, it appears we want "Scale" which is labeled "Scale in X" as the "Y" should automatically follow. That is a "Double" variable. The "Y" value is called "DistortionScaleY" and is also a Double variable. We can set this too but it really doesn't matter.
That means we will then change that last section to now read:
OFXEffect ofx = effect.OFXEffect;
OFXDoubleParameter X = (OFXDoubleParameter)ofx["Scale"];
X.Value = 1.000;
OFXDoubleParameter Y = (OFXDoubleParameter)ofx["DistortionScaleY"];
Y.Value = 1.000;
We'll get our "X" parameter named "Scale" and set it to a value of 1.000. And this will also set the "Y" parameter even though it's automatically the same as the "X" value unless you change other parameters.
Now surrounding it with all the default base code that surrounds all of the scripts we've been creating. You end up with:
using System;
using System.Collections.Generic;
using System.Collections;
using System.IO;
using System.Text;
using System.Windows.Forms;
using System.Globalization;
using System.Drawing;
using System.Runtime;
using System.Xml;
using ScriptPortal.Vegas;
namespace Test_Script
{
public class Class1
{
public Vegas myVegas;
public void Main(Vegas vegas)
{
myVegas = vegas;
foreach (Track myTrack in myVegas.Project.Tracks)
{
if (myTrack.IsVideo())
{
foreach (TrackEvent evnt in myTrack.Events)
{
if (evnt.Selected)
{
VideoEvent vEvent = (VideoEvent)evnt;
string plugInUID = "{Svfx:com.vegascreativesoftware:pictureinpicture}";
PlugInNode fx = myVegas.VideoFX;
PlugInNode plugin = fx.GetChildByUniqueID(plugInUID);
Effect effect = new Effect(plugin);
vEvent.Effects.Add(effect);
OFXEffect ofx = effect.OFXEffect;
OFXDoubleParameter X = (OFXDoubleParameter)ofx["Scale"];
X.Value = 1.000;
OFXDoubleParameter Y = (OFXDoubleParameter)ofx["DistortionScaleY"];
Y.Value = 1.000;
}
}
}
}
}
}
}
public class EntryPoint
{
public void FromVegas(Vegas vegas)
{
Test_Script.Class1 test = new Test_Script.Class1();
test.Main(vegas);
}
}
All the information is there in those tutorials. It's just a matter of adjusting for your specific effect and parameters.
@jetdv Thank you very much for the explanation, I will try to replicate with another plugin. A doubt. Is it possible to automatically open the settings window of the added plug-in? Automatically open the video event FX after the plugin has been added.
@jetdv Because my idea is to add PiP and immediately be able to move the media in the video preview. without even having to click on the Video Event FX icon.
Is it possible to automatically open the settings window of the added plug-in? Automatically open the video event FX after the plugin has been added.
using System;
using System.Collections.Generic;
using System.Collections;
using System.IO;
using System.Text;
using System.Windows.Forms;
using System.Globalization;
using System.Drawing;
using System.Runtime;
using System.Xml;
using ScriptPortal.Vegas;
namespace Test_Script
{
public class Class1
{
public Vegas myVegas;
public void Main(Vegas vegas)
{
myVegas = vegas;
foreach (Track myTrack in myVegas.Project.Tracks)
{
if (myTrack.IsVideo())
{
foreach (TrackEvent evnt in myTrack.Events)
{
if (evnt.Selected)
{
VideoEvent vEvent = (VideoEvent)evnt;
string plugInUID = "{Svfx:com.vegascreativesoftware:pictureinpicture}";
PlugInNode fx = myVegas.VideoFX;
PlugInNode plugin = fx.GetChildByUniqueID(plugInUID);
Effect effect = new Effect(plugin);
vEvent.Effects.Add(effect);
OFXEffect ofx = effect.OFXEffect;
OFXDoubleParameter X = (OFXDoubleParameter)ofx["Scale"];
X.Value = 1.000;
OFXDoubleParameter Y = (OFXDoubleParameter)ofx["DistortionScaleY"];
Y.Value = 1.000;
evnt.OpenVideoEffectUI();
}
}
}
}
}
}
}
public class EntryPoint
{
public void FromVegas(Vegas vegas)
{
Test_Script.Class1 test = new Test_Script.Class1();
test.Main(vegas);
}
}
Thank you so much for this script @jetdv, very very convenient and helpful to have this script sitting on the toolbar, because i use the PIP feature quite so often.
And thank you@m3lquixd for bringing this helpful bit to the forefront and also in refining this script. 👍👍
@jetdv Is it possible to make the script, before adding the PiP, check if the event already has a PiP? If the event already has a PiP, instead of adding another one, the script will only open the PiP adjustment window. PiP's Video Effect UI. If the event does not have a PiP, the script will add it and open the window.
Yes. Note here that we add a new "pipFound" variable after getting the Video Event and defining the UniqueID we're looking for. Then we add a new section to search for that UniqueID:
foreach(Effect eff in vEvent.Effects)
{
if (eff.PlugIn.UniqueID == plugInUID)
{
pipFound = true;
break;
}
}
Next, we only add the effect *IF* pipFound is false - or "not pipFound", the ! means "Not". In either case, the effect window will be opened as that command is left outside of the "if" statement.
using System;
using System.Collections.Generic;
using System.Collections;
using System.IO;
using System.Text;
using System.Windows.Forms;
using System.Globalization;
using System.Drawing;
using System.Runtime;
using System.Xml;
using ScriptPortal.Vegas;
namespace Test_Script
{
public class Class1
{
public Vegas myVegas;
public void Main(Vegas vegas)
{
myVegas = vegas;
foreach (Track myTrack in myVegas.Project.Tracks)
{
if (myTrack.IsVideo())
{
foreach (TrackEvent evnt in myTrack.Events)
{
if (evnt.Selected)
{
VideoEvent vEvent = (VideoEvent)evnt;
string plugInUID = "{Svfx:com.vegascreativesoftware:pictureinpicture}";
bool pipFound = false;
foreach(Effect eff in vEvent.Effects)
{
if (eff.PlugIn.UniqueID == plugInUID)
{
pipFound = true;
break;
}
}
if (!pipFound)
{
PlugInNode fx = myVegas.VideoFX;
PlugInNode plugin = fx.GetChildByUniqueID(plugInUID);
Effect effect = new Effect(plugin);
vEvent.Effects.Add(effect);
OFXEffect ofx = effect.OFXEffect;
OFXDoubleParameter X = (OFXDoubleParameter)ofx["Scale"];
X.Value = 1.000;
OFXDoubleParameter Y = (OFXDoubleParameter)ofx["DistortionScaleY"];
Y.Value = 1.000;
}
evnt.OpenVideoEffectUI();
}
}
}
}
}
}
}
public class EntryPoint
{
public void FromVegas(Vegas vegas)
{
Test_Script.Class1 test = new Test_Script.Class1();
test.Main(vegas);
}
}
jetdv: it is still impossible to press a button on fx panel with script? For example i do 3D stereo editing with 2 cams and always align the left and right views with the "auto correct" button. But with lot of clips this is a hard, repeatable work. (yes, i know Vegasaur can do that, but i search a free solution for this easy task.)
@jetdvI emphasized "PiP's Video Effect UI" because if you have one more plugin in the event, it would open specifically the PiP window, not just the Video Effect UI window.
@jetdv Is it possible to specifically open the PiP window, even having another plugin in the event? I don't think it's possible lol 😅 but you're going to tell me.
Jetdv: thanks, finally i have little time for testing. It should work in Vegas 11 too?
I already have and use the Stereoscopic 3D adjust adding script, which is works by hotkey. Now i like to do the auto alignment automatically, without pressing the button every time.
So i insert these lines in my .JS file, but it doesn't work for some reason:
foreach (Parameter parm in evnt.Effects.Parameters) { if (parm.ParameterType.ToString() == "PushButton") { parm.ParameterChanged(); } }
What could be wrong? Maybe only work in latest Vegas versions? :(
C:\Program Files\Sony\Vegas Pro 11.0\Script Menu\Add_fx\3d-auto.js(28) : Expected ',' or ')' C:\Program Files\Sony\Vegas Pro 11.0\Script Menu\Add_fx\3d-auto.js(28) : Expected ';' C:\Program Files\Sony\Vegas Pro 11.0\Script Menu\Add_fx\3d-auto.js(30) : The list of attributes does not apply to the current context C:\Program Files\Sony\Vegas Pro 11.0\Script Menu\Add_fx\3d-auto.js(31) : Expected ',' or ')' C:\Program Files\Sony\Vegas Pro 11.0\Script Menu\Add_fx\3d-auto.js(31) : Expected ';' C:\Program Files\Sony\Vegas Pro 11.0\Script Menu\Add_fx\3d-auto.js(28) : Variable 'foreach' has not been declared C:\Program Files\Sony\Vegas Pro 11.0\Script Menu\Add_fx\3d-auto.js(33) : Variable 'parm' has not been declared
My code:
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;
}
foreach (Effect effect in evnt.Effects)
{
OFXEffect ofx = effect.OFXEffect;
foreach (OFXParameter parm in ofx.OFXParameters)
{
if (parm.ParameterType.ToString() == "PushButton")
{
parm.ParameterChanged();
}
}
}
}
}
}
catch (errorMsg)
{
MessageBox.Show(errorMsg, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
@relaxvideo Well... you don't need to go through the list of effects because you just added the effect you want to look at. Turns out that var effect = new Effect(plugIn); and foreach (Effect effect were both creating the "effect" variable. Therefore, you were getting an error because the same variable was being defined twice in the same scope. But you don't need it anyway - just use the initial "effect" variable and get rid of the foreach loop looking at the effects list.
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;
}
OFXEffect ofx = effect.OFXEffect;
foreach (OFXParameter parm in ofx.OFXParameters)
{
if (parm.ParameterType.ToString() == "PushButton")
{
parm.ParameterChanged();
}
}
}
}
}
catch (errorMsg)
{
MessageBox.Show(errorMsg, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
C:\Program Files\Sony\Vegas Pro 11.0\Script Menu\Add_fx\nane.js(28) : The list of attributes does not apply to the current context
C:\Program Files\Sony\Vegas Pro 11.0\Script Menu\Add_fx\nane.js(29) : Expected ',' or ')'
C:\Program Files\Sony\Vegas Pro 11.0\Script Menu\Add_fx\nane.js(29) : Expected ';'
C:\Program Files\Sony\Vegas Pro 11.0\Script Menu\Add_fx\nane.js(29) : Variable 'foreach' has not been declared
C:\Program Files\Sony\Vegas Pro 11.0\Script Menu\Add_fx\nane.js(31) : Variable 'parm' has not been declared