Controlling Vegas from C#?

CarlK wrote on 2/19/2010, 7:54 PM
I’d like to write a C# program that can start up Vegas, load a veg, render a range of frames, then close Vegas.
Then this would be done multiple times, on a sequences of frame ranges and a sequence of vegs.

The motivation here is two fold:
1. I think a plugin/effect we’re using is leaking memory. Rendering only a range and then closing Vegas is a way to get the memory back.
2. The film we’re rendering is in several vegs and it would be handy to render then one after the other.

In the past, I’ve written C#/VB programs that controlled Excel. With Excel, you can just say “new Application()” and get a new instance of Excel running. (Here is an web article about Excel Com server: http://www.vbdotnetheaven.com/UploadFile/ggaganesh/ExcelSpreadsheet04182005093012AM/ExcelSpreadsheet.aspx)

Is there any similar way to create (or attach) to an instance of Vegas such that you can then easily program against the object model?

Thanks,
Carl

p.s. This is in support of my 14-year-old son Ben’s film making:
http://slugco.com

Comments

JohnnyRoy wrote on 2/21/2010, 4:18 AM
Hi Carl, As you may already know, in C# you can start a process with this call:

Process.Start(startCommand, scriptArgs);

To start Vegas and run a script, pass it the script as an argument like this:

"-SCRIPT:C:\path_to_script\script_name.cs"

Putting both of those together you would get:

string startCommand = @"C:\Program Files\Sony\Vegas Pro 9.0\vegas90.exe";
string scriptArgs = @"C:\Program Files\Sony\Vegas Pro 9.0\Script Menu\MyRender.cs";
Process.Start(startCommand, scriptArgs);

You can close Vegas by placing the following call in your script:

Application.Exit();

That should get you round-trip into Vegas, run a script, and back out.

Of course, you don't need to write any C# to launch Vegas at all. You could make a simple batch file that loads Vegas, the project, and runs the script, like this:


@echo off
"C:\Program Files\Sony\Vegas Pro 9.0\vegas90.exe" "C:\Project1.veg" "-SCRIPT:C:\Program Files\Sony\Vegas Pro 9.0\Script Menu\MyRender.cs"
"C:\Program Files\Sony\Vegas Pro 9.0\vegas90.exe" "C:\Project2.veg" "-SCRIPT:C:\Program Files\Sony\Vegas Pro 9.0\Script Menu\MyRender.cs"
"C:\Program Files\Sony\Vegas Pro 9.0\vegas90.exe" "C:\Project3.veg" "-SCRIPT:C:\Program Files\Sony\Vegas Pro 9.0\Script Menu\MyRender.cs"


Hope this helps.

~jr