Unterschiede

Hier werden die Unterschiede zwischen zwei Versionen angezeigt.

Link zu dieser Vergleichsansicht

Beide Seiten der vorigen Revision Vorhergehende Überarbeitung
Nächste Überarbeitung
Vorhergehende Überarbeitung
en:vegas_python_faq [2018/10/27 16:46]
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 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: +Yes, the filename including the complete path is available in the variable sys.argvIn Python sys.argv is a string list containing the script filename and all commandline argumentsThe script filename is the first string in the list. 
-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("System.IO") // we need System.IO for Path.GetDirectoryName and Path.Combine 
 +import System.IO 
 +from System.IO import * 
 +import sys 
 +scriptDirectory = Path.GetDirectoryName(sys.argv[0]) 
 +helperFile = Path.Combine(scriptDirectory, "HelperFile.ext"
 +</code> 
 + 
 +=== 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: 
 +<code> 
 +C:\Program Files\VEGAS\VEGAS Pro 16.0\vegas160.exe /SCRIPTARGS pythonscriptfilename /SCRIPTARGS arg1 /SCRIPTARGS arg2 
 +</code> 
 + 
 +  * pythonscriptfilename: path and filename of the pythonscriptfile to be executed 
 +  * 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: 
 +<code> 
 +C:\Program Files\VEGAS\VEGAS Pro 16.0\vegas160.exe /SCRIPTARGS "D:\pythonfile\test.py" /SCRIPTARGS arg1 /SCRIPTARGS arg2 
 +</code> 
 + 
 +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) 
 +</code> 
 + 
 +gives as output:
  
-String scriptDirectory = Path.GetDirectoryName(ScriptPortal.Vegas.Script.File); +["D:\pythonfile\test.py","arg1","arg2"]
-String helperFile = Path.Combine(scriptDirectory, "HelperFile.ext");</del> +
-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:\Users\<username>\Documents\Vegas Application Extensions\VEGASPYTHON\  +  * C:\Users\<username>\Documents\Vegas Application Extensions\VEGASPython_PN\  
-C:\Users\<username>\AppData\Local\VEGAS Pro\14.0\Application Extensions\VEGASPYTHON\   +  C:\Users\<username>\AppData\Local\VEGAS Pro\14.0\Application Extensions\VEGASPython_PN\   
-C:\Users\<username>\AppData\Roaming\VEGAS Pro\14.0\Application Extensions\VEGASPYTHON\  +  C:\Users\<username>\AppData\Roaming\VEGAS Pro\14.0\Application Extensions\VEGASPython_PN\  
-C:\ProgramData\Vegas Pro\14.0\Application Extensions\VEGASPYTHON\    +  C:\ProgramData\Vegas Pro\14.0\Application Extensions\VEGASPython_PN\    
-C:\Users\<username>\AppData\Local\Vegas Pro\Application Extensions\VEGASPYTHON\  +  C:\Users\<username>\AppData\Local\Vegas Pro\Application Extensions\VEGASPython_PN\  
-C:\Users\<username>\AppData\Local\Vegas Pro\Application Extensions\VEGASPYTHON\  +  C:\Users\<username>\AppData\Local\Vegas Pro\Application Extensions\VEGASPython_PN\  
-C:\ProgramData\Vegas Pro\Application Extensions\VEGASPYTHON+  C:\ProgramData\Vegas Pro\Application Extensions\VEGASPython_PN
  
-You must use the subdirectoy VEGSAPYTHON in the same directory where you installed the VEGASPYTHON.dll.+You must use the subdirectoy VEGASPYTHON in the same directory where you installed the VEGASPYTHON.dll.
  
 === 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 '.png' extension appended. For example, if the script is named "My Script.cs", the toolbar image should be named "My Script.py.png". The image must be 16 X 16 pixels and must have 32-bit color depth with an alpha channel for transparency. 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 '.png' extension appended. For example, if the script is named "My Script.cs", the toolbar image should be named "My Script.py.png". The image must be 16 X 16 pixels and must have 32-bit color depth with an alpha channel for transparency.
  
-=== How do create and debug a script using a Visual Studio? ===+=== How do 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:debugging_of_scripts_with_visual_studio_2017|debugging_of_scripts_with_visual_studio_2017]] Please see the page [[en:debugging_of_scripts_with_visual_studio_2017|debugging_of_scripts_with_visual_studio_2017]]
  
Zeile 150: Zeile 194:
 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.
  
-=== Where can I get updates to VEGASPython?+=== Where can I get updates to VEGASPython? ===
  
 You can get the latest VEGASPython version here: [[en:vegas_python_download|VEGASPython]] You can get the latest VEGASPython version here: [[en:vegas_python_download|VEGASPython]]
  
-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 structuresYou can find details of the data structures in the VEGAS Scripting API. 
 + 
 +Example: 
 +<code Python> 
 +print (pyVEGAS.Version) 
 +</code> 
 + 
 +=== 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 project) { +<code Python> 
-    foreach (Track track in project.Tracks) { +def FindSelectedTrack(project): 
-        if (track.Selected) { +    for track in project.Tracks): 
-            return track+        if track.Selected: 
-        } +            return track
-    }+
     return null;     return null;
-}+     
 +print(FindSelectedTrack(pyVEGAS.Project))     
 +</code>
  
 +<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[] FindSelectedEvents(Project project{ +print(FindSelectedEvents(pyVEGAS.Project)) 
-    List<TrackEventselectedEvents = new List<TrackEvent>(); +</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 can be 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.
  
-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's ASR and (in the case of VideoEvents) transition effects. The Fade object has a Curve property which can be set to one of the CurveType enumeration values. The following example gives an event fade in curve the fast type. Every TrackEvent object has FadeIn and FadeOut properties which give you objects that control the event's ASR and (in the case of VideoEvents) transition effects. The Fade object has a Curve property which can be set to one of the CurveType enumeration values. The following example gives an event fade in curve the fast type.
-Language: C# 
  
-evnt.FadeIn.Curve = CurveType.Fast;+ 
 +<code Python> 
 +evnt.FadeIn.Curve = CurveType.Fast 
 +</code>
  
 One tricky aspect of fades comes into play when two events overlap on the same track. In this case, only the trailing event's FadeIn really matters and, to designate the type of fade curve for the leading event, you actually must set the trailing event's ReciprocalCurve property. The following code snippet makes a slow curved fade transition between an event (trailingEvent) and any event on the same track that overlaps its leading edge: One tricky aspect of fades comes into play when two events overlap on the same track. In this case, only the trailing event's FadeIn really matters and, to designate the type of fade curve for the leading event, you actually must set the trailing event's ReciprocalCurve property. The following code snippet makes a slow curved fade transition between an event (trailingEvent) and any event on the same track that overlaps its leading edge:
-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?+</code> 
 +=== 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 +</code>
-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 CreateTransitionEffect(VEGAS vegas, String plugInName)  { +<code Python> 
-    PlugInNode plugIn = vegas.Transitions.GetChildByName(plugInName); +def CreateTransitionEffect(plugInName): 
-    if (null == plugIn) +    plugIn = pyVEGAS.Transitions.GetChildByName(plugInName) 
-        throw new ApplicationException(String.Format("Failed to find plug-in: '{0}'", plugInName)); +    if plugIn==None: 
-    return new Effect(plugIn); +        print("Failed to find plug-in:", plugInName) 
-}+    return Effect(plugIn) 
 +</code>
  
 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("VEGAS Dissolve"); 
-videoEvent.FadeIn.Transition = fadeInTx; 
-fadeInTx.Preset = "Additive Dissolve"; 
-Effect fadeOutTx = CreateTransitionEffect("VEGAS Slide"); 
-videoEvent.FadeOut.Transition = fadeOutTx; 
-fadeOutTx.Preset = "Additive Dissolve"; 
  
 +<code Python>
 +Effect fadeInTx = CreateTransitionEffect("VEGAS Dissolve")
 +videoEvent.FadeIn.Transition = fadeInTx
 +fadeInTx.Preset = "Additive Dissolve"
 +Effect fadeOutTx = CreateTransitionEffect("VEGAS Slide")
 +videoEvent.FadeOut.Transition = fadeOutTx
 +fadeOutTx.Preset = "Additive Dissolve"
 +</code>
 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 "VEGAS". 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 "VEGAS".
  
-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 'File.Open' menu command and will insert tracks if necessary. You can set the cursor position using the CursorPosition of the Vegas object's Transport property. The following method demonstrates how to insert a media file at a specific position on a specific track using the OpenFile method. 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 'File.Open' menu command and will insert tracks if necessary. You can set the cursor position using the CursorPosition of the Vegas object's Transport property. The following method demonstrates how to insert a media file at a specific position on a specific track using the OpenFile method.
-Language: C# 
  
-void InsertFileAt(Vegas vegas, String fileName, int trackIndex, Timecode cursorPosition) {+<code Python> 
 +def InsertFileAt(fileName, trackIndex, cursorPosition):
     // first clear all track selections     // first clear all track selections
-    foreach (Track track in vegas.Project.Tracks) { +    for track in pyVEGAS.Project.Tracks: 
-        track.Selected = false+        track.Selected = false
-    }+
     // select the desired track     // select the desired track
-    vegas.Project.Tracks[trackIndex].Selected = true;+    pyVegas.Project.Tracks[trackIndex].Selected = True
     // set the cursor position     // set the cursor position
-    vegas.Transport.CursorPosition = cursorPosition; +    pyVEGAS.Transport.CursorPosition = cursorPosition 
-    vegas.OpenFile(fileName); +    pyVEGAS.OpenFile(fileName) 
-}+</code>
  
 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 AddVideoEvent(Vegas vegas, String mediaFile, Timecode start, Timecode length) +<code Python> 
-{ +def AddVideoEvent(mediaFile, start, length): 
-    Media media = new Media(mediaFile); +    media = Media(mediaFile) 
-    VideoTrack track = vegas.Project.AddVideoTrack(); +    track = pyVegas.Project.AddVideoTrack() 
-    VideoEvent videoEvent = track.AddVideoEvent(start, length); +    videoEvent = track.AddVideoEvent(start, length) 
-    Take take = videoEvent.AddTake(media.GetVideoStreamByIndex(0)); +    take = videoEvent.AddTake(media.GetVideoStreamByIndex(0)) 
-    return videoEvent; +    return videoEvent 
-}+</code>
  
-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 AddTextEvent(Vegas vegas, VideoTrack track, Timecode start, Timecode length) +<code Python> 
-{+def AddTextEvent(track, start, length):
     // find the text generator plug-in     // find the text generator plug-in
-    PlugInNode plugIn = vegas.Generators.GetChildByName("Titler");+    plugIn = pyVEGAS.Generators.GetChildByName("Titler")
     // create a media object with the generator plug-in     // create a media object with the generator plug-in
-    Media media = new Media(plugIn);+    media = Media(plugIn)
     // set the generator preset     // set the generator preset
-    media.Generator.Preset = "centered";+    media.Generator.Preset = "centered"
     // add the video event     // add the video event
-    VideoEvent videoEvent = track.AddVideoEvent(start, length);+    videoEvent = track.AddVideoEvent(start, length)
     // add the take using the generated video stream     // add the take using the generated video stream
-    Take take = videoEvent.AddTake(media.GetVideoStreamByIndex(0)); +    take = videoEvent.AddTake(media.GetVideoStreamByIndex(0)) 
-    return videoEvent; +    return videoEvent 
-}+</code>
  
-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's VideoMotion property. The VideoMotion object has a Keyframes collection that contains VideoMotionKeyframe objects. Each keyframe has a Position in time relative to the start of the event. Keyframes also have a Bounds polygon representing the four corners of the view-port onto the source media. The best way to manipulate this bounds rectangle is to use the keyframe's MoveBy, ScaleBy, and RotateBy methods. The keyframe's Center defines the point at the center of rotation. Pan and crop settings can be manipulated using the VideoEvent's VideoMotion property. The VideoMotion object has a Keyframes collection that contains VideoMotionKeyframe objects. Each keyframe has a Position in time relative to the start of the event. Keyframes also have a Bounds polygon representing the four corners of the view-port onto the source media. The best way to manipulate this bounds rectangle is to use the keyframe's MoveBy, ScaleBy, and RotateBy methods. The keyframe's Center defines the point at the center of rotation.
  
 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, VideoEvent videoEvent) +<code Python> 
-{+def PanFromLeft(VideoEvent videoEvent):
     // create a new keyframe at 2 seconds.     // create a new keyframe at 2 seconds.
-    VideoMotionKeyframe key1 = new VideoMotionKeyframe(Timecode.FromSeconds(2));+    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
-    int videoWidth = vegas.Project.Video.Width;+    videoWidth = pyVEGAS.Project.Video.Width
     // move the first keyframe just off screen     // move the first keyframe just off screen
-    key0.MoveBy(new VideoMotionVertex(videoWidth, 0)); +    key0.MoveBy(VideoMotionVertex(videoWidth, 0)) 
-}+</code>
  
-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's opacity trim level. You can to set the CompositeLevel property of a VideoTrack object to effect the entire track's opacity trim level.
-Language: C# 
  
-videoTrack.CompositeLevel = 0.5f;+<code Python> 
 +videoTrack.CompositeLevel = 0.
 +</code>
  
 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's FadeIn object: Individual event opacity can be set using the Gain property of the video event's FadeIn object:
-Language: C# 
  
-videoEvent.FadeIn.Gain = 0.5;+<code Python> 
 +videoEvent.FadeIn.Gain = 0.5 
 +</code>
  
-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 pan = audioTrack.Envelopes.FindByType(EnvelopeType.Pan);+<code Python> 
 +pan = audioTrack.Envelopes.FindByType(EnvelopeType.Pan) 
 +</code>
  
 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's name to the name you're looking for. 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's name to the name you're looking for.
-Language: C# 
  
-Envelope FindEnvelopeByName(Envelopes envelopes, String envelopeName) { +<code Python> 
-    foreach (Envelope envelope in envelopes) { +def FindEnvelopeByName(envelopes, envelopeName): 
-        if (envelope.Name == envelopeName) { +    for envelope in envelopes: 
-            return envelope+        if envelope.Name == envelopeName: 
-        } +            return envelope
-    }+
     return null;     return null;
-}+</code>
  
 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 "Chorus: Delay". 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 "Chorus: Delay".
  
-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 volumeEnvelope = new Envelope(EnvelopeType.Volume); +<code Python> 
-audioTrack.Envelopes.Add(volumeEnvelope);+volumeEnvelope = Envelope(EnvelopeType.Volume) 
 +audioTrack.Envelopes.Add(volumeEnvelope) 
 +</code>
  
 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's Points collection. 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's Points collection.
-Language: C# 
  
-EnvelopePoint envelopePoint = new EnvelopePoint(Timecode.FromSeconds(1), 2.0, CurveType.Sharp); +<code Python> 
-envelope.Points.Add(envelopePoint);+envelopePoint = EnvelopePoint(Timecode.FromSeconds(1), 2.0, CurveType.Sharp) 
 +envelope.Points.Add(envelopePoint) 
 +</code>
  
 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's x-coordinate on the timeline. The second argument is the envelope point's value at the given position. This value must lie somewhere between the envelope's Min and Max properties. Envelopes also have a Neutral property which defines the default or middle value for envelope points. The third argument is one of the CurveType enumeration values which represents how the curve following the point should ascend or descend to reach the next point in the envelope. 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's x-coordinate on the timeline. The second argument is the envelope point's value at the given position. This value must lie somewhere between the envelope's Min and Max properties. Envelopes also have a Neutral property which defines the default or middle value for envelope points. The third argument is one of the CurveType enumeration values which represents how the curve following the point should ascend or descend to reach the next point in the envelope.
  
 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's position to a negative value or, in the case of event envelopes, to a time beyond the end of the event. It is also illegal to set a point's value outside the envelope's min/max range. 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's position to a negative value or, in the case of event envelopes, to a time beyond the end of the event. It is also illegal to set a point's value outside the envelope's min/max range.
- 
-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 '.dll' file extension. Application extensions are generally meant to be installed by an installer program but in some cases you may need to add or remove them manually. When VEGAS starts, it looks in the following locations for application extensions. 
- 
-C:\Users\<username>\Documents\Vegas Application Extensions\   
-C:\Users\<username>\AppData\Local\VEGAS Pro\14.0\Application Extensions\  
-C:\Users\<username>\AppData\Roaming\VEGAS Pro\14.0\Application Extensions\  
-C:\ProgramData\Vegas Pro\14.0\Application Extensions\   
-C:\Users\<username>\AppData\Local\Vegas Pro\Application Extensions\ 
-C:\Users\<username>\AppData\Local\Vegas Pro\Application Extensions\ 
-C:\ProgramData\Vegas Pro\Application Extensions\ 
- 
-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' directory in your 'Documents' directory yourself and intaller programs will add extensions to the 'ProgramData' directories. 
- 
-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, VEGAS calls the GetCustomCommands method. You should return a collection of the CustomCommand objects your module implements. This is typically an array of CustomCommand objects but any collection that implements the ICollection interface will work. Each CustomCommand object has an Invoked event which occurs when the user selects the command from the menu, toolbar, or keyboard shortcut. 
-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, "SampleToolCommand"); 
-        cmd.DisplayName = "Hello World"; 
-        cmd.Invoked += this.HandleInvoked; 
-        return new CustomCommand[] { cmd }; 
-    } 
- 
-    void HandleInvoked(Object sender, EventArgs args) { 
-        MessageBox.Show("hello world"); 
-    } 
-} 
- 
-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's LoadDockView method. 
-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, "mySampleViewCommand"); 
- 
-    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("HellowWorldView")) 
-        { 
-            DockableControl dockView = new DockableControl("HellowWorldView"); 
-            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("HellowWorldView"); 
-    } 
-     
-} 
- 
-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's icon in the Extensions menu. 
  

Andere Sprachen
QR-Code
QR-Code en:vegas_python_faq (erstellt für aktuelle Seite)