Unterschiede
Hier werden die Unterschiede zwischen zwei Versionen angezeigt.
Beide Seiten der vorigen Revision Vorhergehende Überarbeitung Nächste Überarbeitung | Vorhergehende Überarbeitung | ||
en:vegas_python_faq [2018/10/27 17:14] hlinke |
en:vegas_python_faq [2020/03/14 16:07] (aktuell) hlinke [Section 1: General] |
||
---|---|---|---|
Zeile 99: | Zeile 99: | ||
=== Is there a way to determine the path of currently running script? === | === Is there a way to determine the path of currently running script? === | ||
- | <del>Yes, the global | + | Yes, the filename including the complete path is available in the variable |
- | Language: C# | + | |
+ | So if your script needs access to a helper file that resides in the same directory, your code might look like this: | ||
+ | |||
+ | <code Python> | ||
+ | clr.AddReference(" | ||
+ | import System.IO | ||
+ | from System.IO import * | ||
+ | import sys | ||
+ | scriptDirectory = Path.GetDirectoryName(sys.argv[0]) | ||
+ | helperFile = Path.Combine(scriptDirectory, | ||
+ | </ | ||
+ | |||
+ | === How do I start a script from the commandline? | ||
+ | |||
+ | Pythonscripts can be started from the commandline together with VEGAS and commandline parameters can be passed to the script. | ||
+ | |||
+ | Example: | ||
+ | < | ||
+ | C:\Program Files\VEGAS\VEGAS Pro 16.0\vegas160.exe /SCRIPTARGS pythonscriptfilename /SCRIPTARGS arg1 /SCRIPTARGS arg2 | ||
+ | </ | ||
+ | |||
+ | * pythonscriptfilename: | ||
+ | * arg1: any text string as argument1 | ||
+ | * arg2: any text string as argument2 | ||
+ | |||
+ | The number of arguments is not limited. | ||
+ | |||
+ | The first /SCRIPTARGS must be the script filename. | ||
+ | |||
+ | Example: | ||
+ | < | ||
+ | C:\Program Files\VEGAS\VEGAS Pro 16.0\vegas160.exe /SCRIPTARGS " | ||
+ | </ | ||
+ | |||
+ | If the filename or a parameter include blanks, then the parameter must be enclosed in ´"" | ||
+ | The pythonscript can access the commandline arguments as it is standard in Python via the variable sys.argv. | ||
+ | This variable contains a list of strings with each argument as a separate string item in the list. | ||
+ | The first item is the scriptfilename. | ||
+ | |||
+ | The python script: | ||
+ | |||
+ | <code python> | ||
+ | for arg in sys.argv: | ||
+ | print (arg) | ||
+ | </ | ||
+ | |||
+ | gives as output: | ||
- | String scriptDirectory = Path.GetDirectoryName(ScriptPortal.Vegas.Script.File); | + | [" |
- | String helperFile = Path.Combine(scriptDirectory, "HelperFile.ext");</ | + | |
- | This feature will be provide in the next uopdate of VEGASPython. | + | |
=== How do I add a script to the Scripting menu? === | === How do I add a script to the Scripting menu? === | ||
Zeile 110: | Zeile 154: | ||
You can add a script to the Extension menu (under Vegas' Tools menu) by placing the script in one of the following directories: | You can add a script to the Extension menu (under Vegas' Tools menu) by placing the script in one of the following directories: | ||
- | C: | + | * C: |
- | C: | + | |
- | C: | + | |
- | C: | + | |
- | C: | + | |
- | C: | + | |
- | C: | + | |
- | You must use the subdirectoy | + | You must use the subdirectoy |
=== How do I add a script to the toolbar? === | === How do I add a script to the toolbar? === | ||
Zeile 132: | Zeile 176: | ||
You can make a custom icon appear for a script you've added to the Scripting menu or toolbar by placing a PNG image in the same folder that contains the script. The PNG file must have the same name as the script with the ' | You can make a custom icon appear for a script you've added to the Scripting menu or toolbar by placing a PNG image in the same folder that contains the script. The PNG file must have the same name as the script with the ' | ||
- | === How do create and debug a script using a Visual Studio? === | + | === How do I create and debug a script using a Visual Studio? === |
- | You can debug VEGASPython scripts usuing Microsoft Visual Studio 2017 as Editor and Debugger. You dnot have to compile the script or do any fancy stuff. | + | You can debug VEGASPython scripts usuing Microsoft Visual Studio 2017 as Editor and Debugger. You do not have to compile the script or do any fancy stuff. |
Please see the page [[en: | Please see the page [[en: | ||
Zeile 156: | Zeile 200: | ||
==== Section 2: Tracks and Events ==== | ==== Section 2: Tracks and Events ==== | ||
- | === How do access the VEGAS attributes? === | + | === How do I access the VEGAS attributes? === |
- | VEGASPython provides a variable pyVEGAS | + | VEGASPython provides a variable pyVEGAS |
Example: | Example: | ||
Zeile 228: | Zeile 272: | ||
<code Python> | <code Python> | ||
- | Effect fadeInTx = CreateTransitionEffect(" | + | Effect fadeInTx = CreateTransitionEffect(" |
- | videoEvent.FadeIn.Transition = fadeInTx; | + | videoEvent.FadeIn.Transition = fadeInTx |
- | fadeInTx.Preset = " | + | fadeInTx.Preset = " |
- | Effect fadeOutTx = CreateTransitionEffect(" | + | Effect fadeOutTx = CreateTransitionEffect(" |
- | videoEvent.FadeOut.Transition = fadeOutTx; | + | videoEvent.FadeOut.Transition = fadeOutTx |
- | fadeOutTx.Preset = " | + | fadeOutTx.Preset = " |
</ | </ | ||
You must pass the full name of the plug-in to the GetChildByName method. The Plug-In Manager window shows the full name of each plug-in. Most built-in plug-ins begin with " | You must pass the full name of the plug-in to the GetChildByName method. The Plug-In Manager window shows the full name of each plug-in. Most built-in plug-ins begin with " | ||
Zeile 270: | Zeile 314: | ||
<code Python> | <code Python> | ||
def AddTextEvent(track, | def AddTextEvent(track, | ||
- | |||
// find the text generator plug-in | // find the text generator plug-in | ||
plugIn = pyVEGAS.Generators.GetChildByName(" | plugIn = pyVEGAS.Generators.GetChildByName(" | ||
Zeile 284: | Zeile 327: | ||
</ | </ | ||
- | === How to I make a script modify the text string in a text event? === | + | === How do I make a script modify the text string in a text event? === |
You can't. Currently, one major shortcoming of the scripting API in VEGAS is that specific parameters of video effects are not accessible to scripts. The text string of text generators are one such parameter. Scripts can only set presets values for a given key frame. | You can't. Currently, one major shortcoming of the scripting API in VEGAS is that specific parameters of video effects are not accessible to scripts. The text string of text generators are one such parameter. Scripts can only set presets values for a given key frame. | ||
Zeile 313: | Zeile 356: | ||
<code Python> | <code Python> | ||
- | videoTrack.CompositeLevel = 0.5f; | + | videoTrack.CompositeLevel = 0.5 |
</ | </ | ||
Zeile 321: | Zeile 364: | ||
<code Python> | <code Python> | ||
- | videoEvent.FadeIn.Gain = 0.5; | + | videoEvent.FadeIn.Gain = 0.5 |
</ | </ | ||
Zeile 331: | Zeile 374: | ||
Language: C# | Language: C# | ||
- | Envelope | + | <code Python> |
+ | pan = audioTrack.Envelopes.FindByType(EnvelopeType.Pan) | ||
+ | </ | ||
All Track objects (AudioTrack and VideoTrack) have an Envelopes collection. So do all BusTrack objects and VideoEvent objects. Envelopes collections also have a HasEnvelope method that allows you to quickly determine whether it contains an envelope of a particular type. | All Track objects (AudioTrack and VideoTrack) have an Envelopes collection. So do all BusTrack objects and VideoEvent objects. Envelopes collections also have a HasEnvelope method that allows you to quickly determine whether it contains an envelope of a particular type. | ||
If you want to find an automation envelope on an audio track, you will need to find it by name. This means you need to iterate through the Envelopes collection and compare each envelope' | If you want to find an automation envelope on an audio track, you will need to find it by name. This means you need to iterate through the Envelopes collection and compare each envelope' | ||
- | Language: C# | ||
- | Envelope | + | <code Python> |
- | | + | def FindEnvelopeByName(envelopes, |
- | if (envelope.Name == envelopeName) { | + | |
- | return envelope; | + | if envelope.Name == envelopeName: |
- | } | + | return envelope |
- | } | + | |
return null; | return null; | ||
- | } | + | </ |
Automation envelopes are named by both effect name and parameter name. For example an automation envelope for the delay parameter of the chorus effect is named " | Automation envelopes are named by both effect name and parameter name. For example an automation envelope for the delay parameter of the chorus effect is named " | ||
- | 3.2: How do I add an envelope to a track or event? | + | === How do I add an envelope to a track or event? |
The first step to add an envelope to a track or event is to create a new envelope of the desired type. The Envelope class constructor can take any of the values in the EnvelopeType enumeration. The next step is to add the new envelope to the appropriate Envelopes collection. | The first step to add an envelope to a track or event is to create a new envelope of the desired type. The Envelope class constructor can take any of the values in the EnvelopeType enumeration. The next step is to add the new envelope to the appropriate Envelopes collection. | ||
- | Language: C# | ||
- | Envelope | + | <code Python> |
- | audioTrack.Envelopes.Add(volumeEnvelope); | + | volumeEnvelope = Envelope(EnvelopeType.Volume) |
+ | audioTrack.Envelopes.Add(volumeEnvelope) | ||
+ | </ | ||
In this case, audioTrack can be any audio track that does not already have a volume envelope. Certain envelope types can only be added to a specific context. For example, you cannot add a volume envelope to a video event. It is currently not possible for a script to add an audio effect automation envelope to an audio track or bus track. | In this case, audioTrack can be any audio track that does not already have a volume envelope. Certain envelope types can only be added to a specific context. For example, you cannot add a volume envelope to a video event. It is currently not possible for a script to add an audio effect automation envelope to an audio track or bus track. | ||
- | 3.3: How do I add points to an envelope? | + | === How do I add points to an envelope? |
You can add points to an envelope in much the same way you add envelopes to a track or event. The first step is to create an EnvelopePoint object then just add it to the envelope' | You can add points to an envelope in much the same way you add envelopes to a track or event. The first step is to create an EnvelopePoint object then just add it to the envelope' | ||
- | Language: C# | ||
- | EnvelopePoint | + | <code Python> |
- | envelope.Points.Add(envelopePoint); | + | envelopePoint = EnvelopePoint(Timecode.FromSeconds(1), |
+ | envelope.Points.Add(envelopePoint) | ||
+ | </ | ||
The code fragment above creates a new envelope point positioned one second after the start of the envelope. The first argument to the EnvelopePoint constructor is its position. The position represents the point' | The code fragment above creates a new envelope point positioned one second after the start of the envelope. The first argument to the EnvelopePoint constructor is its position. The position represents the point' | ||
One rule to keep in mind when adding envelope points is that no two points can have the same position. An exception is thrown if you attempt to add a point with the same position as another. It is illegal to set a point' | One rule to keep in mind when adding envelope points is that no two points can have the same position. An exception is thrown if you attempt to add a point with the same position as another. It is illegal to set a point' | ||
- | |||
- | Section 4: Application Extensions | ||
- | |||
- | 4.1: What are application extensions? | ||
- | |||
- | Application extensions are an advanced form of script that are loaded when VEGAS starts and remain active as long as VEGAS is running. Application extensions can add commands to the Extensions menus under VEGAS' Edit, View, and Tools menus. As with scripts, you can add these commands to VEGAS' toolbar and create keyboard shortcuts for them. | ||
- | |||
- | Applicaton extensions can have greater levels of interactivity than scripts. They can monitor the changes you make to your project and react accordingly. They can create windows that you can dock along side VEGAS' built-in windows. They can also interactivly control playback. | ||
- | |||
- | Unlike scripts, application extensions must be compiled and installed in specific locations before VEGAS can use them. As with scripts (or any program you run on your computer), make sure you trust the source of any application extension you install on your system. | ||
- | |||
- | 4.2: How do I install an application extension? | ||
- | |||
- | Application extensions are contained in .NET assemblies which are program libraries for the .NET runtime that have a ' | ||
- | |||
- | C: | ||
- | C: | ||
- | C: | ||
- | C: | ||
- | C: | ||
- | C: | ||
- | C: | ||
- | |||
- | Different systems and users will have different paths to the various directories but VEGAS and installer programs should find them based on standard Windows APIs. Typically you will manage the 'Vegas Application Extensions' | ||
- | |||
- | 4.3: How do I write a simple "hello world" application extension? | ||
- | |||
- | An application extension starts with a class that implements the ICustomCommandModule interface. This interface has two methods, InitializeModule and GetCustomCommands. VEGAS calls InitializeModule after it creates the module object. After initialization, | ||
- | Language: C# | ||
- | |||
- | using System; | ||
- | using System.Collections; | ||
- | using System.Windows.Forms; | ||
- | using ScriptPortal.Vegas; | ||
- | |||
- | public class SampleModule : ICustomCommandModule { | ||
- | |||
- | public void InitializeModule(Vegas vegas) { } | ||
- | |||
- | public ICollection GetCustomCommands() { | ||
- | CustomCommand cmd = new CustomCommand(CommandCategory.Tools, | ||
- | cmd.DisplayName = "Hello World"; | ||
- | cmd.Invoked += this.HandleInvoked; | ||
- | return new CustomCommand[] { cmd }; | ||
- | } | ||
- | |||
- | void HandleInvoked(Object sender, EventArgs args) { | ||
- | MessageBox.Show(" | ||
- | } | ||
- | } | ||
- | |||
- | Most command modules hold a reference to the Vegas object passed to the InitializeModule method and use it to access VEGAS' project data when the user invokes the commands. The CommandCategory value passed to the CustomCommand constructor determines which Extensions menu contains the command. The second argument to the CustomCommand constructor is its unique name which VEGAS uses to identify the command. You should never change this name because VEGAS uses it to restore the user's toolbar and keyboard binding preferences. This name must be unique so try to pick a name that other application extension authors probably won't use. If VEGAS loads a command with the same name before yours, your command will be ignored. | ||
- | |||
- | The DispalyName property of your CustomCommand appears in the Extension menu item for your command, in the tool-tip text for the toolbar button assigned to your command, and various other user interfaces. | ||
- | |||
- | 4.4: How do I create a window that can be docked in VEGAS' user interface? | ||
- | |||
- | The DockableControl class is special type of UserControl that can be docked in VEGAS' user interface. Typically, you will associate a DockableControl with a CustomCommand that appears in VEGAS' View.Extensions menu. When this command is invoked, your module will create a DockableControl and pass it to the Vegas object' | ||
- | Language: C# | ||
- | |||
- | using System; | ||
- | using System.Drawing; | ||
- | using System.Collections; | ||
- | using System.Windows.Forms; | ||
- | using ScriptPortal.Vegas; | ||
- | |||
- | public class SampleModule : ICustomCommandModule { | ||
- | protected Vegas myVegas = null; | ||
- | | ||
- | public void InitializeModule(Vegas vegas) | ||
- | { | ||
- | myVegas = vegas; | ||
- | } | ||
- | |||
- | CustomCommand myViewCommand = new CustomCommand(CommandCategory.View, | ||
- | |||
- | public ICollection GetCustomCommands() { | ||
- | myViewCommand.DisplayName = "Hello World View"; | ||
- | myViewCommand.Invoked += this.HandleInvoked; | ||
- | myViewCommand.MenuPopup += this.HandleMenuPopup; | ||
- | return new CustomCommand[] { myViewCommand }; | ||
- | } | ||
- | |||
- | void HandleInvoked(Object sender, EventArgs args) { | ||
- | if (!myVegas.ActivateDockView(" | ||
- | { | ||
- | DockableControl dockView = new DockableControl(" | ||
- | Label label = new Label(); | ||
- | label.Dock = DockStyle.Fill; | ||
- | label.Text = "hello world"; | ||
- | label.TextAlign = ContentAlignment.MiddleCenter; | ||
- | dockView.Controls.Add(label); | ||
- | myVegas.LoadDockView(dockView); | ||
- | } | ||
- | } | ||
- | |||
- | void HandleMenuPopup(Object sender, EventArgs args) | ||
- | { | ||
- | myViewCommand.Checked = myVegas.FindDockView(" | ||
- | } | ||
- | | ||
- | } | ||
- | |||
- | The DockableControl is constructed with a unique name string which can be used to activate the window using the ActivateDockView method. If this method returns true, the control has been loaded and VEGAS will bring it to the front of other docked windows. If ActivateDockView returns false, you should construct a new DockableControl and pass it to LoadDockView. | ||
- | |||
- | The MenuPopup event of your CustomCommand occurs when VEGAS shows the Extensions menu that contains the command. This is your opportunity to check if your DockableControl is loaded. You can set the Checked property of your command to indicate whether VEGAS should draw a box around your command' | ||