There are still the RunScriptFile method of the ScriptHost Class. I tried it. It works, but I got then repetitive error messages saying: "An error occurred while processing the undo buffer. You should save your work immediately usig a new project filename and restart Vegas. The reason for the error could not be determined."
Closing and reopening Vegas solve the problem, but it's not very practical!
I tried also this:
import SonicFoundry.Vegas;
var WshShell = new ActiveXObject("WScript.Shell");
var oExec = WshShell.Exec(<script to execute>);
With same results: it works, but Vegas don't work after the running.
Any idea?
Yes, you can start Vegas with a script as a command line parameter and Vegas will automatically run that script upon starting.
If you are trying to start the script by passing parameters to that script, save the parameters in an INI or XML file and have the script read the parameters after it starts.
The problem with all of these options is that you can't pass a parameter in. I have a really nice script that I use with a bunch of projects. But I have to customize it in a few places for each project. So I either have to continually edit and customize each time I run it, or I have to keep a bunch of copies around which is a maintenance nightmare as the script evolves. One response suggested reading parms from an INI file. But then I still have to edit the script to change the INI file name.
I'm a seasoned Java and C++programmer. In those realms, I would simply create an object out of the body of code and use the object in very short scripts that pass the needed parameters.
Am I going about this wrong? I don't know enough about JScript to figure out if I can objectize my code and call it. Am I basically stuck with what I have, or are there alternatives?
I guess my real question is whether there is any way to pass a parm to a script.
It does sound like a GUI with parameter settings is the way to go.
This might eliminate the need to call a script from within a script.
Perhaps list of presets might help you quickly choose a parameter
set. You can use all the classes in the System.Windows.Forms namespace
to create the GUI. You can maybe even add the ability to save preset
data to a file. You can also use the registry and XML files for
persistence.
There is a global variable called ScriptFile that tells you the full
path of the currently running script. This can help you save data in a
logical place. More details here:
The .NET scripting framework is structured differently from something
like a command-line app and there is no traditional (argc/argv) way to
pass parameters to a script. However, I am open to ideas for the next
version of Vegas... suggestions are welcome.
One approach I've considered is to make the XmlDocument object that is
created from the script configuration file available to the script
itself in a global variable... call it something like ScriptConfigDoc.
The script configuration file is parsed each time the script is run
anyway so there is minimal cost to making it available. Then, if the
script wants to persist some data in its config file, it can
add/remove/alter nodes in ScriptConfigDoc and then call a simple
method like:
I'm all for anything to assist automation, and anything that will help me write code once and reuse.
I could do a GUI, but the parameters are typically input and output directory paths, which are not short. I don't want to have to enter long path names every time I run the script.
Maybe I'm asking the wrong question. What I would really like to do is create my own library with a few reusable classes. Then I can write tiny little scripts that basically do nothing but call my classes. I know C++ and Java extensively, but limited experience with JScript. I've looked at the JScript site to get more info and a little tutorial. But haven't really found anything useful. I know this is out of the realm of the Vegas scripting forum. But 1) how hard is it to create my own JScript packages (does it require add'l build tools)? And 2) where could I get a good tutorial on how to do it.
You can achieve your goal by writing a .net assembly that contains all
of your helper classes and methods. There's a FAQ on using custom
assemblies here.
You can create assemblies in JScript, C#, or whatever.
Thanks so much for the info. That's exactly what I'm looking for.
But I need one more piece of information. I'm a very experienced java J2EE programmer, but no experience in .net. Can you give me a couple of pointers or web sites on how to create .net assemblies from jscript files? I just don't know the .net tool set. All the .net basics sites I found on google offer 5 day courses. All I want is an idea of what kind of compiler/etc I need to invoke to create the .dll.