This section contains a variety of techniques and recipes for using Softimage commands in scripts.
![]()
|
All examples are written in the VBScript language. |
As you build, test, and refine scripts, you can choose to run only part of them. This lets you concentrate on a particular portion of your script. There are two ways of doing this:
• “Comment out” lines that you do not want to run. To do this in VBScript, add an apostrophe (') at the beginning of the line. When you want to run the line again, remove the apostrophe.
• To run a contiguous block of lines, select them in the editing pane before running the script. If text is selected, only the selection is executed. Be careful to select complete lines.
It’s a good idea to declare variables before using them. Not only does it make your scripts a bit faster, it also makes it easier to find and fix problems in your code. For example, to declare variables in VBScript:
dim myVar1, myVar2, myVar3
In VBScript, you can force variables to be defined before they are used by including the following statement in the global code at the beginning of your script:
Option Explicit
When scripting, be careful not to use words that are reserved by the host scripting language as variable names, object or parameter names in the scene, and so on. For example, “type” is a reserved word in VBScript. At first it might not be obvious why the following fails:
set return = SomeCommand(arg1, arg2, type)
If you declared the variable, this would be the line that fails:
dim type
Softimage restricts the valid characters in element names to a–z, A–Z, 0–9, the hyphen (-), and the underscore (_) to keep them variable-safe for scripting. Invalid characters are automatically converted to underscores. In addition, element names cannot start with a digit: in this case, Softimage automatically prepends an underscore.
This even applies to the scene’s name as returned by ActiveProject.ActiveScene.Name: you cannot append “.scn” to that value to reliably get the scene’s file name. To get the scene’s file name, you should use ActiveProject.ActiveScene.Parameters("Filename").
![]()
|
Although the hyphen is a legal character in Softimage element names, there are some issues with using it. Names with hyphens cannot be used in expressions because the hyphen is used to represent the subtraction operator. In addition, you cannot use shortcut notation in scripts. For example, the following line does not work: LogMessage myObj.my-param Instead, you must use the long form: LogMessage myObj.Parameters("my-param").value
|
When setting parameter values by scripting, you can bypass the maximum and minimum values allowed. Be careful not to set a value outside the allowable range, or it may cause unpredictable results.
If you want to write scripts that can run on either Windows or Linux, you need to follow these principles:
• Use forward slashes (/) in paths instead of back slashes (\). Windows recognizes forward slashes, but back slashes are treated as escape characters on Linux.
• Remember that paths and file names are case-sensitive on Linux.
• Do not use drive letters in paths.
• Do not use spaces in paths and file names.
• Be aware of other limitations on Linux, as described in the next section.
There are currently certain limitations with scripting on Linux:
• Softimage provides limited versions of Scripting.TextStream (Close, Readline, Writeline, AtEndOfStream) and Scripting.Dictionary (Add, Item).
• When using the VBScript split() command, use a large number for the count argument. For example:
parsed = split(textstring, ".", 2000)
Here are some tricks for optimizing your scripts.
Making Custom Commands
When you run a custom command, only one line is logged to the history window. This can substantially speed up the execution of the script.
You can make a custom command even while you are still developing a script. Create a custom command as described in Creating Script-based Custom Commands, then reopen the script file as described in Editing Script Implementations. Once you save the script file, the modified script will be called by the command button.
Reducing Unnecessary Calls
Another way to speed up your scripts is to check your arguments within the scripting language before making a potentially unnecessary call to an Softimage command. For example:
... If Not IsEmpty (myList) Then AddToSelection myList End If
Turning Off Command Logging
You can increase the speed of execution by turning off command logging while running a script. This will have little impact on custom commands, however, since these log only the custom command name and not every line of code. See Disabling Command Logging Temporarily.
Autodesk Softimage v.7.5