Scripting language choice

WayneM wrote on 5/17/2011, 9:29 PM
I want to make use of the scripting capability of both Vegas Pro and Sound Forge. My programming was limited to BASIC and I've done some Visual Basic ages ago.

I see there are several languages I can use and would appreciate a suggestion of which one to settle on. Any way I will have to learn as I go. I guess it depends on which language will already have the most scripts for these products already available, since I may end up making changes to meet my needs.

Thanks!

Comments

jetdv wrote on 5/18/2011, 9:48 AM
Most examples you'll find today are in C#. Older examples are typically in JScript. There are very few examples in Visual Basic but it can be used.
WayneM wrote on 8/7/2011, 10:40 AM
Thank you Jetdv. Sorry for the delay, I expected an email notice it there was a reply. What gives with that? Sony emails me about every OTHER thing :-)

Is there a way in Vegas Pro (10.0E) to create a simple script by capturing keystrokes? (EDIT: The word I was searching for was MACROs.)

I also use Vegas for multi-track (16 to 24) audio only mixing and mastering. When I bring in a bunch of tracks and after they are trimmed for a take I slog thru each Audio event and change the properties to UNcheck Looping and to Check Normalize. It seems this might be a natural for scripting, but what do I know. I also often want to go thru and refresh the Normailzation of all events.

Is there a common location where people are sharing this kind of functionality? I think I can pick up the How To if I can see some simple scripts and make modifications for my needs.

Thanks much.

JohnnyRoy wrote on 8/7/2011, 12:45 PM
> [I]When I bring in a bunch of tracks and after they are trimmed for a take I slog thru each Audio event and change the properties to UNcheck Looping and to Check Normalize. It seems this might be a natural for scripting, but what do I know. I also often want to go thru and refresh the Normailzation of all events. [/I]

There are already commercial scripts that can do this and a whole lot more. VASST Ultimate S Pro can take care of those audio tasks for you in a single mouse click. Excalibur may be able to as well. If you don't have one of these productivity tools you are missing out on a lot of the automation that they provide.

~jr
jetdv wrote on 8/8/2011, 10:45 AM
I agree with John. You'll be much better off just grabbing one of the commercial script. John wrote Ultimate S - I wrote Excalibur. They'll both do what you want to do and both have free trial periods. Just to get your feet wet, here's a really, really OLD script that normalizes - just copy the text into a file name "Normalize.js"


/**
* This script normalizes all Audio Events in the current project.
* This script works best if you run it after all event peaks have
* been built.
*
* Revision Date: Feb. 10, 2003
* Revised: Aug 8, 2011 to change "SonicFoundry" to "Sony"
**/

import Sony.Vegas;

var trackEnum : Enumerator = new Enumerator(Vegas.Project.Tracks);
while (!trackEnum.atEnd()) {
var track : Track = Track(trackEnum.item());
if (track.IsAudio()) {
var eventEnum : Enumerator = new Enumerator(track.Events);
while (!eventEnum.atEnd()) {
var audioEvent : AudioEvent = AudioEvent(eventEnum.item());
audioEvent.Normalize = true;
eventEnum.moveNext();
}
}
trackEnum.moveNext();
}


Steve Mann wrote on 8/11/2011, 7:51 PM
Do the Vb scripts need to be compiled before use?
jetdv wrote on 8/12/2011, 7:44 AM
Not necessarily. Save this code as "Version.vb" and then you can run it from Tools - Scripting - Run Script:


' This most simple VBScript displays the version of the Vegas
' application in a message box. Notice that any script that talks to
' Vegas will import the Sony.Vegas.Script namespace. Please also
' notice that the portion of script code that Vegas will invoke must be
' placed in a subroutine named "Main" which is in a module named
' "MainModule".
'
' Revision Date: Jan. 30, 2003.

imports System.Windows.Forms
imports Sony.Vegas

Public Module MainModule
Sub Main
MessageBox.Show("VegasApp.Version: " & VegasApp.Version)
End Sub
End Module


Here's the equivalent "Version.js" file:


/**
* This most simple JScript displays the version of the Vegas
* application in a message box. Notice that any script that talks to
* Vegas will import the Sony.Vegas namespace.
*
* Revision Date: Jan. 30, 2003.
**/
import System.Windows.Forms;
import Sony.Vegas;

MessageBox.Show("Vegas.Version: " + Vegas.Version);


And, of course, the same thing as "Version.cs"


/**
* This most simple C# script displays the version of the Vegas
* application in a message box. Notice that any script that talks to
* Vegas will import the Sony.Vegas namespace.
**/

using System.Windows.Forms;
using Sony.Vegas;

public class EntryPoint
{
Vegas myVegas;

public void FromVegas(Vegas vegas)
{
myVegas = vegas;

MessageBox.Show("Vegas.Version: " + myVegas.Version);
}
}



And then here's a larger VB script for your perusal called "ExpandEvents.vb"


'****************************************
'Script created by Lars Netzel 2003-07-14
'****************************************
'This script will expand all selected
'events by a number of frames provided by
'the user to get events to overlap each
'other.
'****************************************

Imports Sony.Vegas
Imports System.Windows.Forms.Form
Imports System.Windows.Forms
Imports System.Collections
Imports System
Imports System.Drawing
Imports System.ComponentModel
Imports System.IO

Public Module MainModule

Public Sub Main()
ExpandSelectedEvent(GetInputValue())
End Sub

Public Function GetInputValue() As Integer
'prompt User For Input
Dim InputValue As String
InputValue = InputBox("Type the number of frames you want to expand event with")
Try
GetInputValue = CInt(InputValue)
Catch objE As Exception
MessageBox.Show("Input was not a valid number")
GetInputValue = 0
End Try
End Function

Private Sub ExpandSelectedEvent(ByVal NumberofFrames As Integer)
Dim anEnum As IEnumerator
Dim SelectedTracks As Integer
anEnum = VegasApp.Project.Tracks.GetEnumerator
While anEnum.MoveNext 'Loop through the tracks
If CType(anEnum.Current(), Sony.Vegas.Track).IsVideo Then
Dim EventEnum As IEnumerator
EventEnum = CType(anEnum.Current(), Sony.Vegas.Track).Events.GetEnumerator
While EventEnum.MoveNext 'Loop through Events
Dim TrackEvent As Sony.Vegas.TrackEvent
TrackEvent = CType(EventEnum.Current, Sony.Vegas.TrackEvent)
If TrackEvent.Selected Then
Dim addFrames As New Timecode()
Dim start As Timecode
Dim length As Timecode
'Event length will be added with NumberofFrames*2 long but start NumberofFrames earlier
addFrames.FrameCount = (0 - NumberofFrames)
start = TrackEvent.Start.op_Addition(TrackEvent.Start, addFrames)
addFrames.FrameCount = (NumberofFrames * 2)
length = TrackEvent.Length.op_Addition(TrackEvent.Length, addFrames)
'Make change
TrackEvent.AdjustStartLength(start, length, False)
End If
End While
End If
End While
End Sub

End Module

Steve Mann wrote on 8/15/2011, 8:05 PM
Thanks for the samples, but here's this error I get when I try to run "Version.vb":

System.NotSupportedException: Language not supported.
at Sony.Vegas.ScriptHost.RunScript(Boolean fCompileOnly)

Do I need to install Visual Basic to get the runtime modules? But, if that were the case than so would any user of VB scripts. So my original question: do I need to compile the script in Visual Basic?
jetdv wrote on 8/16/2011, 6:14 AM
That script was actually originally written for Vegas 4.0. However, I just now tested it in Vegas Pro 9 (32-bit) and it ran just fine. I then tested it in Vegas Pro 10 64-bit and got the same error as you. So I tried it in Vegas Pro 10 32-bit and it ran fine. To further test, I then tried it in Vegas Pro 9 64-bit and it also failed. So it could simply be that 64-bit versions of Vegas do not support VB scripts.

Personally, I would use C# instead. Almost all examples you see today are written in C#.
TheHappyFriar wrote on 8/16/2011, 7:01 PM
Isn't it true that Vegas can also run dll's compiled from any language?
Steve Mann wrote on 8/16/2011, 8:55 PM
C# or not to C#....
The problem is that for years I was writing VB programs and am almost an expert.

The last time I wrote anything in C was when the K&R book was the bible.

Thanks for testing.

But, since Vegas-64 won't run VB scripts in interpretive mode, do you think it might work if I compile the script as a dll? (Makes testing difficult, though).

Steve
Gary James wrote on 10/3/2011, 2:59 PM
Yes, for the most part you can run a script compiled in a DLL, but it must meet certain criteria.

1. I've found that it must be written using the Microsoft .Net v2.0 Framework to be compatible with all versions of Vegas.

2. If you compile a 32 bit DLL, it only works with 32 bit Sony Vegas. Same is true for 64 bit DLLs.

3. Your best choice is to select "Any CPU" as the Visual Studio project Solution Platform. This creates a DLL that works with both 32 and 64 bit versions of Vegas.

4. You must include a reference to the Sony.Vegas DLL in your project. It doesn't matter if it's the 32 or 64 bit DLL. But the version of Vegas that you select your DLL from determines the earliest version of Vegas that your DLL will work with. For example: when I used the DLL from my Sony Vegas 9.0 installation, then my DLL didn't work on Sony Vegas v8.0. But if my DLL was from my v8.0 installation, the DLL worked on Vegas 8.0 and later.

Gary ...
jetdv wrote on 10/4/2011, 11:28 AM
Gary, your #2 is incorrect. I have a single 32-bit compile of Excalibur that runs fine in both 32-bit and 64-bit versions of Vegas Pro.
Gary James wrote on 10/4/2011, 11:45 AM
It's been a while since I compiled a SCRIPT dll, but the last time I tried it with Vegas Pro 8, I had to make two different versions for 32 & 64 bit modes.

Excalibur is an Extension. I wonder if that makes a difference? Also, if you are running 32 bit Excalibur under 64 bit Sony Vegas Pro, I would assume it must be running in 32 bit mode, not 64 bit mode, right?

I compiled my Timeline Tools extension using the "Any CPU" project setting because it creates a dll that runs in the same bit mode as the host application.
jetdv wrote on 10/4/2011, 1:14 PM
I have never had to compile multiple versions running as either a script or a custom command. It runs in 64-bit under 64-bit Vegas and 32-bit under 32-bit Vegas.

Montage Magic is a different story, though. I have a separate module that I call to do the face detection. I had to compile that module in both 32-bit and 64-bit. Now the single custom command DLL determines if it's running 32-bit or 64-bit and then calls the proper face detection DLL.
Gary James wrote on 10/4/2011, 4:26 PM
You've been doing Vegas scripts and extensions far longer than I have, so I'll defer to your expertise on this. I'm just confused why I experienced what I saw. I must have introduced some other unknown variable into the mix that I wasn't aware of.

By the way, thanks again for all the help you gave me while I was learning how to program Sony Vegas extensions. Your knowledge and willingness to share it, was gratefully appreciated.