Unterschiede
Hier werden die Unterschiede zwischen zwei Versionen angezeigt.
Nächste Überarbeitung | Vorhergehende Überarbeitung | ||
en:vegas_python_faq [2018/10/27 15:47] hlinke angelegt |
en:vegas_python_faq [2020/03/14 16:07] (aktuell) hlinke [Section 1: General] |
||
---|---|---|---|
Zeile 7: | Zeile 7: | ||
- | === Section 1: General === | + | ==== Section 1: General |
- | == What is VEGASPython Scripting? == | + | === What is VEGASPython Scripting? |
When we speak of scripting in VEGAS, we're not referring to what may first come to mind for many of you, a written description of the scenes and dialog in a video production. Rather, we're referring to programmatic access to the internal data structures in VEGAS projects that allows you to automate things that you might normally do via the GUI. This may help you perform repetitive tasks, integrate with external applications, | When we speak of scripting in VEGAS, we're not referring to what may first come to mind for many of you, a written description of the scenes and dialog in a video production. Rather, we're referring to programmatic access to the internal data structures in VEGAS projects that allows you to automate things that you might normally do via the GUI. This may help you perform repetitive tasks, integrate with external applications, | ||
- | == Which scripting languages does VEGAS use? == | + | === Which scripting languages does VEGAS use? === |
VEGAS uses the .NET framework to provide its scripting interface. VEGAS can execute C#, JScript, and Visual Basic script files directly. You do not need to compile them first. VEGAS can also execute scripts written in other .NET languages but those scripts must be compiled first. | VEGAS uses the .NET framework to provide its scripting interface. VEGAS can execute C#, JScript, and Visual Basic script files directly. You do not need to compile them first. VEGAS can also execute scripts written in other .NET languages but those scripts must be compiled first. | ||
Zeile 21: | Zeile 21: | ||
Microsoft' | Microsoft' | ||
- | 1.3: Do I need to be a programmer to write scripts? | + | With the VEGASPython extension Vegas can now also execute Scripts programmed in Python. |
- | For the most part, yes. Although the .NET Framework provides several high level languages and numerous class libraries, it will be very difficult | + | === Do I need to be a programmer |
- | 1.4: How do I create a script | + | With VEGASPython and the possibility to use the Python Programing language |
- | Most scripts are just source code (ASCII text) files with a .cs, .js, or .vb extension so any text editor will do the trick. Notepad may be the best choice among standard Windows applications. Of course, you can use software development tools such as Microsoft Visual Studio or GNU Emacs to help create | + | === How do I create |
- | Compiled | + | All Python |
+ | In the following we assume that you use the interactive VEGASPython editor if nothing else is defined. | ||
- | 1.5: How do I write a simple "hello world" script? | + | === How do I write a simple "hello world" script? |
- | VEGAS uses several .NET script engine technologies to execute scripts. By default, VSA compilers are used for JScript and Visual Basic. Perhaps | + | Enter the following text in the interactive VEGASPython editor: |
- | Language: JScript | + | |
- | import System.Windows.Forms; | + | <code Python> |
- | import ScriptPortal.Vegas; | + | print(" |
+ | </ | ||
- | MessageBox.Show("hello world"); | + | Click in the manu on "Execute Script". |
- | When VEGAS executes Visual Basic scripts using the VSA script engine, it begins with the Main subroutine in the MainModule module: | + | You will see in the output window |
- | Language: Visual Basic | + | |
- | imports System.Windows.Forms | + | Very simple. |
- | imports ScriptPortal.Vegas | + | |
- | Public Module MainModule | + | Remember |
- | Sub Main | + | |
- | MessageBox.Show(" | + | |
- | End Sub | + | |
- | End Module | + | |
- | + | ||
- | The VSA script engines were made obsolete with the introduction of .NET 2.0 and the introduction of new CodeDOM compilers. VEGAS uses a CodeDOM compiler | + | |
- | Language: | + | |
+ | <code C#> | ||
using System.Windows.Forms; | using System.Windows.Forms; | ||
using ScriptPortal.Vegas; | using ScriptPortal.Vegas; | ||
Zeile 64: | Zeile 57: | ||
} | } | ||
} | } | ||
+ | </ | ||
- | At some point in the future, you can expect VEGAS to stop supporting VSA scripts since the .NET Framework will eventually drop the VSA engines. Most of the sample code in this document is written in C#. | + | You see the difference ? |
- | 1.6: How do I use a script that has been posted on the web as a .txt file? | + | === How do I use a script that has been posted on the web as a .txt file? === |
- | You can copy the entire contents of the script file from your browser window and paste it into a new document in your text editor. Using Notepad, you can "Save As" | + | You can copy the entire contents of the script file from your browser window and paste it into a the interactive VEGASPython Editor. With "Save As" |
- | An nice alternative to using copy and paste is to right click in the browser window and choose "View Source" | ||
- | 1.7: Do scripts pose a security risk to my computer? | + | === Do scripts pose a security risk to my computer? |
Yes, scripts can be a security risk to your computer. A script run by VEGAS has the power to do almost anything: delete files, read files, write files, execute programs, access the Internet, access files on your local network, etc. You should always examine the contents of a script before running it and, if you don't understand what it is really doing, you should not run it unless it comes from a trusted source. In general, you should take the same precautions for scripts that you would take for any executable program you download. | Yes, scripts can be a security risk to your computer. A script run by VEGAS has the power to do almost anything: delete files, read files, write files, execute programs, access the Internet, access files on your local network, etc. You should always examine the contents of a script before running it and, if you don't understand what it is really doing, you should not run it unless it comes from a trusted source. In general, you should take the same precautions for scripts that you would take for any executable program you download. | ||
- | 1.8: How do I use my own .NET assembly | + | === How do I use my own or other .NET assemblies |
- | By default, VEGAS loads the following | + | VEGASPython is based on IRONPython. IRONPython allows to easily access .NET assemblies |
- | mscorlib.dll | + | Here is an example for System.QWindows.Forms |
- | | + | |
- | System.Drawing.dll | + | |
- | System.Windows.Forms.dll | + | |
- | System.Xml.dll | + | |
- | These assemblies cover most of the classes that scripts will use. However, occasionally a script will need to use classes that are not defined in the assemblies above including ones you've written yourself. In these cases, scripts must have a configuration file that tells VEGAS which extra assemblies to load. | + | <code Python> |
+ | import clr | ||
+ | clr.AddReference('System.Windows.Forms' | ||
+ | import System.Windows.Forms as WinForms | ||
+ | clr.AddReference(' | ||
+ | import ScriptPortal.Vegas as VEGAS | ||
+ | from ScriptPortal.Vegas import * | ||
+ | </ | ||
- | Each script can have a configuration file that specifies extra .NET assemblies used by the script. The configuration file is an XML file with the same file name as the script except it has the ' | + | === How do I use my own or other Python Modules from within |
- | The following provides an example of a configuration file for a script that references several extra assemblies: | + | In VEGASPython you can import Python modules using the standard Python syntax: |
- | Language: XML | + | |
- | <?xml version=" | + | <code Python> |
- | < | + | import sys |
- | < | + | import os |
- | < | + | from sys import * |
- | < | + | </code> |
- | </ScriptSettings> | + | |
- | The root XML element of the configuration file is named ScriptSettings. This element can contain any number of AssemblyReference elements. The inner text of each AssemblyReference element contains the file name of an assembly DLL. For assemblies that are in the GAC (Global Assembly Cache... this includes most assemblies that ship with the .NET Framework), a full path is not required. The resolver attribute, when set to " | + | As VEGASPython |
- | One problem in the current release of VEGAS is that VB scripts can not access assemblies in that are not either in the GAC or in the same directory as the VEGAS executable. It is possible, however, to add your assembly | + | === Is there a way to determine |
- | 1.9: Is there a way to determine | + | Yes, the filename including the complete path is available in the variable sys.argv. In Python sys.argv is a string list containing |
- | Yes, the global variable ScriptPortal.Vegas.Script.File contains the full path of the currently executing script. | + | So if your script needs access to a helper file that resides in the same directory, your code might look like this: |
- | Language: C# | + | |
- | String | + | <code Python> |
- | String | + | clr.AddReference(" |
+ | import System.IO | ||
+ | from System.IO import * | ||
+ | import sys | ||
+ | scriptDirectory = Path.GetDirectoryName(sys.argv[0]) | ||
+ | helperFile = Path.Combine(scriptDirectory, | ||
+ | </ | ||
- | 1.10: How do I add a script | + | === How do I start a script |
- | You can add a script | + | Pythonscripts |
- | C:\Users\< | + | Example: |
- | C:\Users\<username>\AppData\Local\Vegas Pro\14.0\Script Menu\ | + | <code> |
- | C:\Users\< | + | C:\Program Files\VEGAS\VEGAS Pro 16.0\vegas160.exe /SCRIPTARGS pythonscriptfilename /SCRIPTARGS arg1 /SCRIPTARGS arg2 |
- | C: | + | </code> |
- | C:\Users\<username>\AppData\Local\Vegas Pro\Script Menu\ | + | |
- | C: | + | |
- | C: | + | |
- | Different systems | + | * pythonscriptfilename: |
+ | * arg1: any text string as argument1 | ||
+ | * arg2: any text string as argument2 | ||
- | 1.11: How do I add a script to the toolbar? | + | The number of arguments is not limited. |
- | To add a script to the toolbar, | + | The first / |
- | 1.12: How do I assign a keyboard shortcut to a script? | + | Example: |
+ | < | ||
+ | C:\Program Files\VEGAS\VEGAS Pro 16.0\vegas160.exe /SCRIPTARGS "D:\pythonfile\test.py" | ||
+ | </ | ||
- | To assign a keyboard shortcut to a script, first it must be located | + | If the filename or a parameter include blanks, then the parameter |
+ | The pythonscript | ||
+ | This variable contains a list of strings with each argument as a separate string item in the list. | ||
+ | The first item is the scriptfilename. | ||
- | 1.13: How do I make a custom icon appear for a script | + | The python |
- | You can make a custom icon appear | + | <code python> |
+ | for arg in sys.argv: | ||
+ | print (arg) | ||
+ | </ | ||
- | Alternatively, | + | gives as output: |
- | Language: XML | + | |
- | <?xml version="1.0" encoding=" | + | ["D:\pythonfile\test.py"," |
- | < | + | |
- | < | + | |
- | </ | + | |
- | The inner text of the IconFile element is either | + | === How do I add a script to the Scripting menu? === |
- | 1.14: How do create and debug a script | + | You can add a script |
- | You must create a compiled script to debug it using a Visual Studio. To create a Visual Studio project for a VEGAS script, you will typically follow these steps (for Visual Studio 2012... other versions will have similar steps): | + | * C: |
+ | * C: | ||
+ | * C: | ||
+ | * C: | ||
+ | * C: | ||
+ | * C: | ||
+ | * C:\ProgramData\Vegas Pro\Application Extensions\VEGASPython_PN\ | ||
- | In Visual Studio, select | + | You must use the subdirectoy VEGASPYTHON |
- | In the New Project dialog, select the Class Library template under the Visual C# / Windows project type. | + | |
- | Name your new project, choose its location, and click OK to dismiss the New Project dialog. For this example, we will name our project " | + | |
- | Select the ' | + | |
- | Select the Browse tab and select ScriptPortal.Vegas.dll which is located | + | |
- | Add references for any other assemblies your script will use. For example, | + | |
- | Edit your script. Typically, you will change the name of the auto-generated class (Class1) to EntryPoint. | + | |
- | At this point, you should get your script | + | === How do I add a script to the toolbar? === |
- | Language: C# | + | |
- | using System; | + | To add a script to the toolbar, first it must be located in the VEGASPython Scripting folders detailed above. Once added to the Extensionmenu, |
- | using System.Collections.Generic; | + | |
- | using System.Text; | + | |
- | using System.Windows.Forms; | + | |
- | using ScriptPortal.Vegas; | + | |
- | namespace SampleScript1 | + | === How do I assign a keyboard shortcut to a script? === |
- | { | + | |
- | public class EntryPoint | + | |
- | { | + | |
- | public void FromVegas(Vegas vegas) | + | |
- | { | + | |
- | MessageBox.Show(vegas.Version); | + | |
- | } | + | |
- | } | + | |
- | } | + | |
- | The following steps describe how to debug your script. | + | To assign a keyboard shortcut |
- | First build the solution | + | === How do I make a custom icon appear for a script |
- | Open the project properties using the ' | + | |
- | In the Debug tab of the project properties, set the Start Action to 'Start external program' | + | |
- | Save the project. | + | |
- | Set your breakpoints in your script. | + | |
- | Start debugging (select the ' | + | |
- | In VEGAS, select the ' | + | |
- | When you run your precompiled | + | You can make a custom icon appear for a script |
- | 1.15: How do I print debug messages from my script? | + | === How do I create and debug a script |
- | You can print debug messages using the System.Diagnostics.Debug.WriteLine method. These messages are visible in your debugger' | + | You can debug VEGASPython |
- | Language: XML | + | Please see the page [[en:debugging_of_scripts_with_visual_studio_2017|debugging_of_scripts_with_visual_studio_2017]] |
- | <?xml version=" | ||
- | < | ||
- | < | ||
- | </ | ||
- | The compiler options required for debug output depend on which language you are using to write your script. The example provided will work for C# scripts. | + | === How do I print debug messages from my script? === |
- | 1.16: How do I prevent debugger failures when my script accesses Cineform templates? | + | You can print debug messages using the Python print() function. These messages are visible in the output window. |
- | This problem is caused by the Cineform codec dll. You will need to quit VEGAS, find the file named CFHD.DLL | + | <code Python> |
+ | print(" | ||
+ | </ | ||
- | 1.17: My question is not answered in the FAQ, where can I get more help? | + | === My question is not answered in the FAQ, where can I get more help? === |
The Scripting Forum is a good place to ask questions. The forum is frequently monitored by VEGAS staff and friendly VEGAS users who have considerable skills and experience. Questions posted in the forum occasionally make their way into this FAQ. | The Scripting Forum is a good place to ask questions. The forum is frequently monitored by VEGAS staff and friendly VEGAS users who have considerable skills and experience. Questions posted in the forum occasionally make their way into this FAQ. | ||
- | 1.18: Where can I get updates to the scripting SDK? | + | === Where can I get updates to VEGASPython? === |
- | The VEGAS Pro Scripting SDK web page will have a link to download | + | You can get the latest |
- | Section 2: Tracks and Events | + | ==== Section 2: Tracks and Events |
- | 2.1: How do I find the currently selected track or event? | + | === How do I access the VEGAS attributes? === |
+ | VEGASPython provides a variable pyVEGAS which is of the type VEGAS and provides the interface to all VEGAS internal data structures. You can find details of the data structures in the VEGAS Scripting API. | ||
+ | |||
+ | Example: | ||
+ | <code Python> | ||
+ | print (pyVEGAS.Version) | ||
+ | </ | ||
+ | |||
+ | === How do I find the currently selected track or event? | ||
You can find the currently selected track or event by iterating through each track and event and examining the Selected property. The following functions provide an example of this: | You can find the currently selected track or event by iterating through each track and event and examining the Selected property. The following functions provide an example of this: | ||
- | Language: C# | ||
- | Track FindSelectedTrack(Project | + | <code Python> |
- | | + | def FindSelectedTrack(project): |
- | if (track.Selected) { | + | |
- | return track; | + | if track.Selected: |
- | } | + | return track |
- | } | + | |
return null; | return null; | ||
- | } | + | |
+ | print(FindSelectedTrack(pyVEGAS.Project)) | ||
+ | </ | ||
+ | <code Python> | ||
+ | def FindSelectedEvents(project): | ||
+ | selectedEvents = [] | ||
+ | for track in project.Tracks: | ||
+ | for trackEvent in track.Events: | ||
+ | if trackEvent.Selected: | ||
+ | selectedEvents.Add(trackEvent) | ||
+ | return selectedEvents | ||
- | TrackEvent[] | + | print(FindSelectedEvents(pyVEGAS.Project)) |
- | List<TrackEvent> selectedEvents = new List< | + | </code> |
- | foreach (Track track in project.Tracks) { | + | |
- | foreach (TrackEvent trackEvent in track.Events) { | + | |
- | if (trackEvent.Selected) { | + | |
- | selectedEvents.Add(trackEvent); | + | |
- | } | + | |
- | } | + | |
- | } | + | |
- | return selectedEvents.ToArray(); | + | |
- | } | + | |
- | Note that multiple tracks and events selected at the same time. The first function returns only the first selected track while the second function returns all of the selected events. Events can be selected in tracks that are not selected. | + | Note that multiple tracks and events |
- | 2.2: How do I set the fade type (curve) for an event? | + | === How do I set the fade type (curve) for an event? |
Every TrackEvent object has FadeIn and FadeOut properties which give you objects that control the event' | Every TrackEvent object has FadeIn and FadeOut properties which give you objects that control the event' | ||
- | Language: C# | ||
- | evnt.FadeIn.Curve = CurveType.Fast; | + | |
+ | <code Python> | ||
+ | evnt.FadeIn.Curve = CurveType.Fast | ||
+ | </ | ||
One tricky aspect of fades comes into play when two events overlap on the same track. In this case, only the trailing event' | One tricky aspect of fades comes into play when two events overlap on the same track. In this case, only the trailing event' | ||
- | Language: C# | ||
- | trailingEvent.FadeIn.Curve = CurveType.Slow; | + | <code Python> |
- | trailingEvent.FadeIn.ReciprocalCurve = CurveType.Slow; | + | trailingEvent.FadeIn.Curve = CurveType.Slow |
- | + | trailingEvent.FadeIn.ReciprocalCurve = CurveType.Slow | |
- | 2.3: How do I make a one second dissolve at the beginning and end of a video event? | + | </ |
+ | === How do I make a one second dissolve at the beginning and end of a video event? | ||
You can add a dissolve (or any transition) to an event using its FadeIn and FadeOut properties. First you can set the length of the transition to the desired amount: | You can add a dissolve (or any transition) to an event using its FadeIn and FadeOut properties. First you can set the length of the transition to the desired amount: | ||
- | Language: C# | ||
- | videoEvent.FadeIn.Length = Timecode.FromSeconds(1); | + | <code Python> |
- | + | videoEvent.FadeIn.Length = Timecode.FromSeconds(1) | |
- | or | + | </ |
- | Language: C# | + | |
- | + | ||
- | videoEvent.FadeOut.Length = Timecode.FromSeconds(1); | + | |
For video events, you can use a transition effect by creating a new instance of an Effect object using a transition PlugInNode then assign it to the Transition property of the appropriate Fade. To create a new transition effect, you must first find the appropriate PlugInNode. To find a transition node by name, use the GetChildByName method of the Transitions root node. The following function creates a new transition effect given its plug-in name: | For video events, you can use a transition effect by creating a new instance of an Effect object using a transition PlugInNode then assign it to the Transition property of the appropriate Fade. To create a new transition effect, you must first find the appropriate PlugInNode. To find a transition node by name, use the GetChildByName method of the Transitions root node. The following function creates a new transition effect given its plug-in name: | ||
- | Language: C# | ||
- | Effect | + | <code Python> |
- | | + | def CreateTransitionEffect(plugInName): |
- | if (null == plugIn) | + | plugIn = pyVEGAS.Transitions.GetChildByName(plugInName) |
- | | + | if plugIn==None: |
- | return | + | |
- | } | + | return Effect(plugIn) |
+ | </ | ||
Now you can set the event fade transitions and assign their preset: | Now you can set the event fade transitions and assign their preset: | ||
- | Language: C# | ||
- | |||
- | Effect fadeInTx = CreateTransitionEffect(" | ||
- | videoEvent.FadeIn.Transition = fadeInTx; | ||
- | fadeInTx.Preset = " | ||
- | Effect fadeOutTx = CreateTransitionEffect(" | ||
- | videoEvent.FadeOut.Transition = fadeOutTx; | ||
- | fadeOutTx.Preset = " | ||
+ | <code Python> | ||
+ | Effect fadeInTx = CreateTransitionEffect(" | ||
+ | videoEvent.FadeIn.Transition = fadeInTx | ||
+ | fadeInTx.Preset = " | ||
+ | Effect fadeOutTx = CreateTransitionEffect(" | ||
+ | videoEvent.FadeOut.Transition = fadeOutTx | ||
+ | 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 " | ||
- | 2.4: How do I add media to the timeline? | + | === How do I add media to the timeline? |
You can use the OpenFile method of the VEGAS object to add a media file to the selected track at the current cursor position. The OpenFile method works much like the ' | You can use the OpenFile method of the VEGAS object to add a media file to the selected track at the current cursor position. The OpenFile method works much like the ' | ||
- | Language: C# | ||
- | void InsertFileAt(Vegas vegas, String | + | <code Python> |
+ | def InsertFileAt(fileName, | ||
// first clear all track selections | // first clear all track selections | ||
- | | + | |
- | track.Selected = false; | + | track.Selected = false |
- | } | + | |
// select the desired track | // select the desired track | ||
- | | + | |
// set the cursor position | // set the cursor position | ||
- | | + | |
- | | + | |
- | } | + | </ |
Sometimes you need more control of how you add media to the project. You can build events on the timeline by constructing media, tracks, events, and take objects individually: | Sometimes you need more control of how you add media to the project. You can build events on the timeline by constructing media, tracks, events, and take objects individually: | ||
- | Language: C# | ||
- | VideoEvent | + | <code Python> |
- | { | + | def AddVideoEvent(mediaFile, |
- | | + | media = Media(mediaFile) |
- | | + | track = pyVegas.Project.AddVideoTrack() |
- | | + | videoEvent = track.AddVideoEvent(start, |
- | | + | take = videoEvent.AddTake(media.GetVideoStreamByIndex(0)) |
- | return videoEvent; | + | return videoEvent |
- | } | + | </ |
- | 2.5: How do I add a text event to the timeline? | + | === How do I add a text event to the timeline? |
You can add a text event to the timeline by constructing a Media object from the text generator effect and adding the video event and take to the track. | You can add a text event to the timeline by constructing a Media object from the text generator effect and adding the video event and take to the track. | ||
- | Language: C# | ||
- | VideoEvent | + | <code Python> |
- | { | + | def AddTextEvent(track, |
// find the text generator plug-in | // find the text generator plug-in | ||
- | | + | plugIn = pyVEGAS.Generators.GetChildByName(" |
// create a media object with the generator plug-in | // create a media object with the generator plug-in | ||
- | | + | media = Media(plugIn) |
// set the generator preset | // set the generator preset | ||
- | media.Generator.Preset = " | + | media.Generator.Preset = " |
// add the video event | // add the video event | ||
- | | + | videoEvent = track.AddVideoEvent(start, |
// add the take using the generated video stream | // add the take using the generated video stream | ||
- | | + | take = videoEvent.AddTake(media.GetVideoStreamByIndex(0)) |
- | return videoEvent; | + | return videoEvent |
- | } | + | </ |
- | 2.6: 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. | ||
- | 2.7: How do I modify the pan/crop settings of a video event from a script? | + | === How do I modify the pan/crop settings of a video event from a script? |
Pan and crop settings can be manipulated using the VideoEvent' | Pan and crop settings can be manipulated using the VideoEvent' | ||
The following function moves a video event into view from a position off screen over a two second period. | The following function moves a video event into view from a position off screen over a two second period. | ||
- | Language: C# | ||
- | void PanFromLeft(Vegas vegas, | + | <code Python> |
- | { | + | def PanFromLeft(VideoEvent videoEvent): |
// create a new keyframe at 2 seconds. | // create a new keyframe at 2 seconds. | ||
- | | + | key1 = VideoMotionKeyframe(Timecode.FromSeconds(2)) |
// add the new keyframe | // add the new keyframe | ||
- | videoEvent.VideoMotion.Keyframes.Add(key1); | + | videoEvent.VideoMotion.Keyframes.Add(key1) |
// get the first keyframe | // get the first keyframe | ||
- | VideoMotionKeyframe key0 = videoEvent.VideoMotion.Keyframes[0]; | + | VideoMotionKeyframe key0 = videoEvent.VideoMotion.Keyframes[0] |
// get the width of the project | // get the width of the project | ||
- | | + | videoWidth = pyVEGAS.Project.Video.Width |
// move the first keyframe just off screen | // move the first keyframe just off screen | ||
- | key0.MoveBy(new VideoMotionVertex(videoWidth, | + | key0.MoveBy(VideoMotionVertex(videoWidth, |
- | } | + | </ |
- | 2.8: How do I set the opacity of a video track or event? | + | === How do I set the opacity of a video track or event? |
You can to set the CompositeLevel property of a VideoTrack object to effect the entire track' | You can to set the CompositeLevel property of a VideoTrack object to effect the entire track' | ||
- | Language: C# | ||
- | videoTrack.CompositeLevel = 0.5f; | + | <code Python> |
+ | videoTrack.CompositeLevel = 0.5 | ||
+ | </ | ||
You can also add a composite level envelope to the video track (described below) if you need to the opacity to change over time. | You can also add a composite level envelope to the video track (described below) if you need to the opacity to change over time. | ||
Individual event opacity can be set using the Gain property of the video event' | Individual event opacity can be set using the Gain property of the video event' | ||
- | Language: C# | ||
- | videoEvent.FadeIn.Gain = 0.5; | + | <code Python> |
+ | videoEvent.FadeIn.Gain = 0.5 | ||
+ | </ | ||
- | Section 3: Envelopes | + | ==== Section 3: Envelopes |
- | 3.1: How do I find a particular envelope for a given track or event? | + | === How do I find a particular envelope for a given track or event? |
To find an envelope by type, you can use the FindByType method of the appropriate Envelopes collection. | To find an envelope by type, you can use the FindByType method of the appropriate Envelopes collection. | ||
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' | ||