General

What is VEGAS 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, and implement customized features.

Which scripting languages does VEGAS use?

VEGAS uses the .NET framework to provide its scripting interface. VEGAS can execute C# 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.

Although C# can be easy to learn, it certainly helps to have programming experience before you try to write a VEGAS script.

Microsoft's .NET Product Documentation web site has more information about the .NET Framework and the C# programming language.

Do I need to be a programmer to write scripts?

For the most part, yes. Although the .NET Framework provides several high level languages and numerous class libraries, it will be difficult to write effective scripts without computer programming experience. In fact, sometimes scripts can be more difficult to write than typical C or C++ applications because the development tools and debugging facilities may not be as advanced. However, sometimes existing scripts can be tweaked a little to meet your specific needs. Don't be afraid to play around with scripts to alter and enhance their behavior.

How do I create a script for VEGAS?

There are three types of scripts in VEGAS;

  • Compile on demand scripts
  • Pre-compiled, scripts
  • Application extension module, scripts

Compile on demand scripts are simple (ASCII text) files containing the script statements which are compiled by VEGAS at the time the script is run. These files have a ".cs" extension and can be created with any text editor. Notepad is a reasonable choice among standard Windows applications. Of course, you can use software development tools such as Microsoft Visual Studio or another programmer's editor to help create scripts.

Pre-compiled, scripts use the same source code files as "Compile on demand" scripts but are compiled before use in VEGAS into a binary file with a ".dll" extension, called a .NET assembly. The script source files are typically compiled by a coomand-line tool from the Microsoft .NET SDK, or Microsoft Visual Studio.

Application extension modules are a more advanced versions of a "Pre-compiled" script that seemlessly integrate with the VEGAS UI. They are discussed in detail by a separate question below.

How do I write a simple "hello world" script?

When VEGAS runs a C# script, execution begins with the FromVegas class method (function) within the class named "EntryPoint", like this:

using System.Windows.Forms;
using ScriptPortal.Vegas;

public class EntryPoint
{
    public void FromVegas(Vegas vegas)
    {
        MessageBox.Show("hello world");
    }
}
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" to specify the script file name. You can name it anything you want but make sure to name the file with the ".cs" extension. Also make sure to choose "All Files" as the "Save as type", otherwise Notepad will append a .txt extension to the file.

An nice alternative to using copy and paste is to right click in the browser window and choose "View Source" which will launch Notepad with the contents of the script. Then just "Save As" as directed above.

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.

How do I use my own .NET assembly from within a script?

Yes. By default, VEGAS loads the following .NET assemblies, making them available for every script that is run:

  • mscorlib.dll
  • System.dll
  • 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 needs to use classes that are not defined in the assemblies listed above, such as ones you've written yourself. In these cases, scripts need a companion configuration file which informs VEGAS of the additional .NET assembly files to load.

The configuration file is an XML file with the same file name as the script with the extension '.config' appended. For example, if your script is named "MyScript.cs", its configuration file would be named "MyScript.cs.config". The configuration file must be placed in the same directory as the script.

The following provides an example of a configuration file for a script that references several extra assemblies:

<?xml version="1.0" encoding="UTF-8" ?>
<ScriptSettings>
  <AssemblyReference>System.Data.dll</AssemblyReference>
  <AssemblyReference resolver="local">LocalUtilities.dll</AssemblyReference>
  <AssemblyReference>C:\MyAssemblies\VegasHelpers.dll</AssemblyReference>
</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 "local", tells VEGAS to look for the referenced assembly in the same directory as the script. Otherwise, you should specify the full path to the assembly. The local resolver attribute allows you to distribute your script, its configuration file, and helper assemblies without hard coding any paths. You just need to keep them in the same directory.

If desired, you can add your own assembly to the GAC by using the gacutil program (See the .NET Framework documentation for more details).

Is there a way to determine the path of currently running script?

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:

String scriptDirectory = Path.GetDirectoryName(ScriptPortal.Vegas.Script.File);
String helperFile = Path.Combine(scriptDirectory, "HelperFile.ext");
How do I add a script to the Scripting menu?

You can add a script to the Scripting menu (under Vegas' Tools menu) by placing the script in one of the following directories:

C:\Users\<username>\Documents\Vegas Script Menu\ 
C:\Users\<username>\AppData\Local\Vegas Pro\22.0\Script Menu\
C:\Users\<username>\AppData\Roaming\Vegas Pro\22.0\Script Menu\
C:\ProgramData\Vegas Pro\22.0\Script Menu\
C:\Users\<username>\AppData\Local\Vegas Pro\Script Menu\
C:\Users\<username>\AppData\Roaming\Vegas Pro\Script Menu\
C:\ProgramData\Vegas Pro\Script Menu\

Different systems and users will have different paths to the various documents and settings directories but VEGAS and installer programs should find them based on standard Windows APIs. Typically, you will manage the 'Vegas Script Menu' in 'Documents' yourself. Installers will use one of the other directories depending on the script's version compatibility, whether the script should appear for all users, etc. After you place the script in one of these directories, it will appear in the Scripts menu the next time you launch VEGAS or after you select the "Rescan Script Menu Folder" menu item.

How do I add a script to the toolbar?

To add a script to the toolbar, first it must be located in one of the Scripting menu folders detailed above. Once added to the Scripting menu, you can add a script to the toolbar using the 'Customize Toolbar' dialog in VEGAS' Options menu. The available scripts are listed at the bottom of of the available toolbar button list.

How do I assign a keyboard shortcut to a script?

To assign a keyboard shortcut to a script, first it must be located in one of the Scripting menu folders detailed above. Once added to the Scripting menu, you can create a keyboard shortcut for the script using the 'Customize Keyboard' dialog in VEGAS' Options menu. The available scripts begin with the 'Script' keyword and are available under any context.

How do I make a custom icon appear for a script in the Scripting menu or toolbar?

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.cs.png". The image must be 16 X 16 pixels and must have 32-bit color depth with an alpha channel for transparency.

Alternatively, you can use the script's configuration file to specify the script's icon. In the configuration file, an IconFile element contains the name of the PNG file to use. For example:

<?xml version="1.0" encoding="UTF-8" ?>
<ScriptSettings>
  <IconFile>C:\Icons\Icon1.png</IconFile>
</ScriptSettings>

The inner text of the IconFile element is either a full path or a file name in the same directory as the script.

How do create a script using Visual Studio?

To create a Visual Studio project for a VEGAS script, you will typically follow these steps (for Visual Studio 2022... other versions will have similar steps):

  • In Visual Studio, select the 'File.New.Project...' menu item.
  • 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 "SampleScript1"
  • Select the 'Project.Add Reference...' menu item.
  • Select the Browse tab and select ScriptPortal.Vegas.dll which is located in the VEGAS install directory (typically in C:\Program Files\VEGAS\Vegas Pro...).
  • Add references for any other assemblies your script will use. For example, the System.Windows.Forms assembly (located in the .NET tab of the Add Reference dialog) is frequently used.
  • 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 be ready to build (compile). For example, the following code provides a very simple example.

    
    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Windows.Forms;
    using ScriptPortal.Vegas;
    
    namespace SampleScript1
    {
        public class EntryPoint
        {
            public void FromVegas(Vegas vegas)
            {
                MessageBox.Show(vegas.Version);
            }
        }
    }