There are several ways to run scripts inside Softimage:
You can run scripts directly from the script editor as described in the next section below.
You can create a custom command to run a script from a button on a custom toolbar.
You can run a custom command automatically whenever the frame or selection changes as described in Running Commands Automatically.
You can disable property editor automatic inspection.
You can run scripts from synoptic views or the Net View as described in the Softimage User's Guide.
You can bind scripts and commands to events so that they are triggered automatically in response to specific actions and states. For more information, see Custom Events.
You can turn off command logging while your scripts are running. This speeds up the execution of your scripts.
Running Scripts from the Script Editor
You can run a script directly from the script editor. This is particularly useful while you are testing and debugging your script before creating a custom command.
When run from the script editor, only global code (that is, script fragments that appear outside of a discrete function or subroutine) is executed. Note that procedures are still executed if they are called from global code.
If one or more lines are selected when you run a script from the script editor, only those lines are executed. If nothing is selected, the entire contents of the editing pane are executed.
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.
Property Editor Automatic Inspection
Certain commands, usually commands that create objects like CreatePrim and CreateLayer, trigger automatic inspection of the new object's property editor. In other words, when these commands run, the property editor for the newly created object opens. When you run scripts that use these commands from the Script Editor, automatic inspection is always disabled.
However, for scripts that use these commands that are run outside of the Script Editor (for example, a self-installing plug-in invoked from a menu item or button), automatic inspection is only disabled in this cases:
The user set their own AutoInspect preference to false for the current session (Softimage always resets it back to true every time it launches).
The self-installing plug-in explicitly sets AutoInspect preference to false for the duration of the plug-in (Softimage always reverts to the original setting as it was before the plug-in was invoked). This can be done either with the SetUserPref command or the Preferences object:
// via SetUserPref command SetUserPref(siAutoInspect, false); SetUserPref("AutoInspectEnabled", false); // via Preferences object var oPrefs = Application.Preferences; var oAutoInspect = oPrefs.SetPreferenceValue("Interaction.autoinspect", false);
Disabling automatic inspection is recommended because it improves the performance of your plug-in and reduces user frustration.
Running Commands Automatically
You can run custom commands or any native Autodesk Softimage command automatically in either of the following ways:
You can also bind scripts and commands to events so that they are triggered automatically in response to specific actions and states. For more information, see Custom Events.
To run a script, you must first create a custom command as described in Custom Commands.
To run scripts automatically when an object is selected in a geometry view
Choose File User Preferences from the Autodesk Softimage main menu.
On the Interaction page, enter the command name and any parameters in the OnSelectionChange Command box. For example, in VBScript syntax:
LogMessage GetValue("SelectionList")
This setting is stored with your user preferences and is used in all scenes.
Disabling Command Logging Temporarily
You can disable command logging temporarily while your scripts are running. This speeds up the execution of scripts considerably, because each command is not echoed in the script editor's history pane.
As an alternative to this procedure, you can also disable command logging permanently from the User Preferences dialog box — see Disabling and Enabling Command and Message Logging.
To disable command logging temporarily
The following snippet demonstrates how to get the user's current preference for command logging, turn logging off, and then restore the user's preference after your script is finished.
// Get current state var prefs = Application.Preferences; var originalsetting = prefs.GetPreferenceValue( "scripting.cmdlog" ); // Disable command logging if ( !originalsetting ) { prefs.SetPreferenceValue( "scripting.cmdlog", false ); } // // Do your stuff // // Restore logging setting to the way it was prefs.SetPreferenceValue( "scripting.cmdlog", originalsetting );
Disable message logging temporarily using "scripting.msglog" in place of "scripting.cmdlog".
Disable the automatic opening of property editors using "Interaction.autoinspect". See Property Editor Automatic Inspection for more details.
To stop execution of a script while it's running, press Ctrl+Break (Ctrl+Pause on some keyboards). You may need to press this key combination a few times because the keyboard is checked only before each native Autodesk Softimage command is executed.
Ctrl+Break does not work with PerlScript. The scripting engine does not stop on errors.
Softimage will stop at the time the next Softimage command is executed. Therefore if the script is caught in its own endless loop or is only calling Object Model methods and properties it cannot be halted.