C# vs. JScript for Vegas Scripts?

2G wrote on 1/21/2007, 9:52 PM
I have noticed that almost all of the scripts shipped with Vegas have been converted to C# from JScript (I'm assuming .cs extensions are C#...). I'm curious about the rationale and implications of that. What does C# provide that JScript doesn't? Is there any increased function in C#? More importantly, should I read anything into this that perhaps Vegas is considering dropping JScript support? I have many many many huge scripts that I have written that I live by. If I need to start migrating to C# for whatever reason, I'd like a lot of advanced warning.

Can someone enighten me on what's going on with C# and JScript as a Vegas scripting language.

Comments

jetdv wrote on 1/22/2007, 7:00 AM
I've switched to writing in C#. I like that I can edit in Visual Studio, add a reference to Vegas, and code completion works. It also allows me to more easily provide a GUI.

Since both C# and JScript are part of .NET, I'm not anticipating support for JScript to be dropped - however, I'm not part of the development team. Like you, I also have several JScript scripts and all are continuing to work fine in Vegas 7.
2G wrote on 1/22/2007, 11:54 AM
I don't use Visual Studio. So the tooling improvements don't help me. Is the code simpler for GUIs, or is it just easier to create the same amount of code using VS?

Are there any functional things that are available on in C#. My main 'dream' is to create common classes that I can reuse multiple scripts. I've been told there's no way to do that in JScript with Vegas. By chance does that capability exist in C#?

Also, my other dream is to be able to invoke a script from the command line and have it launch an instance of Vegas (where I can pass in command line parameters). For example, I'd love to be able to pass a folder name on a command line, have it launch Vegas, and batch render the entire folder. I have been told in the past "not in my lifetime...". Any improvement here with C#?

Thanks again.

2G
jetdv wrote on 1/22/2007, 2:27 PM
Yes, c# will let you build components that are reusable across multiple scripts.

As for the GUI, with c#, it's wysiwyg designing - you just draw the displays without worrying about the details behind the code.
2G wrote on 1/22/2007, 3:13 PM
Well the component capabiity just put me over the edge... I'm moving to C#. I am so sick of trying to maintain the same common blocks of code in 100 scripts. Thanks for the info.

Where might I find an example of how to create a common class, or is it as simple as just putting a .cs file by that name in the same directory as the script?

Thanks again.
jetdv wrote on 1/22/2007, 6:43 PM
Compile the common routines into a DLL file and then include that DLL file in your other scripts. There are tons of C# books available.
smog wrote on 1/28/2007, 9:56 PM
I discovered there is one other alternative. IronPython. You can't use it directly
but with a tiny JScript stub, that invokes the IronPython engine you can then
develop using python ;-)
Teetow wrote on 1/29/2007, 6:46 AM
For me, there's no alternative to the C# / Visual Studio combo.

If you keep all your Vegas scripts in one solution, each project will show up as an entry in the "Add Reference -> Project" dialog. I have one foundation library upon which all my other scripts are built, so if I add that as a reference, all my classes are automatically included.

Being able to hook onto a running instance of Vegas and stepping through my code is simply a prerequesite to efficient debugging. Also, I can't imagine going back to text editors - if nothing else but for the reason that I almost never have to look things up in the SDK documentation when I'm in VS. All the Vegas classes are included in the code completion tool, and I can use the class inspector for the rest.
Frank Z wrote on 3/18/2007, 12:11 PM
The idea behind .Net is that you can use your language of choice within the platform. That means if you're more comfortable with JScript, it's available and likewise for C# and Visual Basic. You shouldn't have to worry about your old scripts being obsoleted as JavaScript (the inspiration of JScript) is becoming a common scripting language in a good amount of apps.

I think C# is preferred mainly by developers who want stricter code and prefer the language. I am coming from the Java world so C# made the most sense because believe it or not it looks more like Java than JScript does!
Frank Z wrote on 3/18/2007, 12:17 PM
"Are there any functional things that are available on in C#. My main 'dream' is to create common classes that I can reuse multiple scripts. I've been told there's no way to do that in JScript with Vegas. By chance does that capability exist in C#?"

Yes. You could also theoretically access your C# classes from your JScripts. What you'd need to do is build a dll with C#. I'll try to dig up the article that discussed this.

As far as getting it to run from a command line and have it launch Vegas, you can do it in either. From what I've read, rendering is scriptable so it's 100% feasible.
JohnnyRoy wrote on 3/19/2007, 4:50 AM
> Yes. You could also theoretically access your C# classes from your JScripts. What you'd need to do is build a dll with C#. I'll try to dig up the article that discussed this.

Yup, compile your script into a DLL, let's say you call it "MyRenderScript.dll". If you want to access this from a JScript file called, "DoRender.js" you would create a config XML file called "DoRender.js.config" with the following contents:

<?xml version="1.0" encoding="UTF-8" ?>
<ScriptSettings>
<AssemblyReference IsLocal="true">MyRenderScript.dll</AssemblyReference>
</ScriptSettings>

To use the contents of this dll in your JScript, just add an import statement for the Namespace that you used. So if you used the Namespace "MyTools" then add
import MyTools;
at the top of your JScript code and you can access any public classes in the DLL.

> As far as getting it to run from a command line and have it launch Vegas, you can do it in either.

The command line syntax looks like this:
vegas70.exe -SCRIPT:"C:\Program Files\Sony\Vegas 7.0\Script Menu\DoRender.js"
Which is basically the word -SCRIPT: with the absolute path to your script file. If you start in the Vegas 7 directory you could use a relative path like -SCRIPT:".\Script Menu\DoRender.js".

~jr
Frank Z wrote on 3/29/2007, 7:56 AM
Now my followup question to the scripting part would be... Can I also write a script that would instantiate Vegas as an object and render that way. For example...

Bear with me I'm writing this from the top of my head so it's not going to be syntactically correct.

Vegas vegas = new Sony.Vegas;
RenderTemplate template = <whatever>;
vegas.openProject("MyProject");
vegas.Render("FinishedProduct.avi", template);

I'm assuming it would work like any other dotnettable application. Am I right?
JohnnyRoy wrote on 3/30/2007, 3:44 AM
> I'm assuming it would work like any other dotnettable application. Am I right?

No. Vegas provides the hosting environment in which the script is run and the vegas object is valid. You cannot instantiate a Sony.Vegas object yourself. If you want to render from the Windows command line you would have to invoke Vegas and pass it the script to run like I showed above:
vegas70.exe -SCRIPT:"C:\Program Files\Sony\Vegas 7.0\Script Menu\DoRender.js"
That is the only way to get a vegas object.

~jr
Teetow wrote on 4/1/2007, 5:38 PM
Simply put, it's Vegas that calls your script, not the other way around.

This is the reason you have to have an Entrypoint class with a function called FromVegas() in it - it's what Vegas looks for when you launch your script.
DavidMcKnight wrote on 4/15/2007, 8:36 PM
I don't write Vegas scripts but I am a C# programmer. I was recently shown an opensource IDE for C# if you don't want to use Visual Studio. Might be worth a look...

http://www.icsharpcode.net/OpenSource/SD/
SonyPJM wrote on 5/30/2007, 2:54 PM
My biggest concern in regards to choosing a scripting language is not so much about the language itself as it is the scripting engine that is used... CodeDOM vs. VSA.

Microsoft has deprecated VSA so I think CodeDOM, in which ever language you prefer, is the primary concern. The good thing is it typically is very easy to convert from VSA to CodeDOM... just wrap your existing stuff up in a EntryPoint class and FromVegas method and replace references to the Vegas object with an instance member. Although it is nice to have JScripts that don't need the EntryPoint.FromVegas stuff, support for that may go away some day.

I have experienced some limitations in JScript when accessing structures and some class methods. Also, some of the .net 2.0 language features are not supported in JScript. I also find that the C# compiler is quicker.
LarryP wrote on 6/7/2007, 7:05 PM
Will the free Visual Studio Express C# product work or how about the Orcas "community technology peview"?
jetdv wrote on 6/8/2007, 7:30 AM
I know Express c# has been used.