Running Scripts

 
 
 

There are several ways to run scripts in Softimage:

You can turn off command logging in the history pane while your scripts are running to speed up the execution of your scripts.

NoteScripts can no longer change the number of undo levels permanently. This prevents problems that occur when scripts set the number of undo levels to 0 to increase performance, and then fail to set it back or terminate abnormally.

Running Scripts in the Script Editor

Running a script in the script editor is particularly useful while you are testing and debugging your script before creating a custom command.

When run in the script editor, only the global code (script fragments that appear outside of a discrete function or subroutine) is executed. The procedures are still executed if they are called from the global code.

If you select one or more lines before running a script in the script editor, only these lines are executed. If nothing is selected, the entire content in the editing pane is executed.

To run a script in the script editor:

Do one of the following:

  • Click the run icon on the command bar.

  • Press F5.

  • Select Edit Run from the command bar.

  • Right-click in the editing pane and select Run from the pop-up menu.

Running Parts of Scripts

You can choose to run only a part of a script. This lets you concentrate on a particular part of your script. There are two ways of doing this:

  • Comment out the lines that you do not want to run. For example, to do this in VBScript, add an apostrophe (') at the beginning of a 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. Make sure to select complete lines.

Property Editor Automatic Inspection

Usually commands that create objects like CreatePrim and CreateLayer trigger automatic inspection of the new object's property editor. When you run these commands, the property editor for the newly created object opens. When you run scripts that use these commands in the script editor, automatic inspection is always disabled.

However, if these commands are used in scripts 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 these cases:

  • If you set the AutoInspect preference to false for the current session (Softimage always resets it back to true each time it is launched).

  • The self-installing plug-in explicitly sets AutoInspect preference to false for the duration of the plug-in. You can do this either with the SetUserPref command or the Preferences object:

// Using SetUserPref command
SetUserPref(siAutoInspect, false);
SetUserPref("AutoInspectEnabled", false);

// Using 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.

Running Commands Automatically

You can run custom commands or native Softimage commands automatically in the following ways:

  • Whenever an object is selected.

  • Whenever you change frames.

  • 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. For more information about custom commands, see Custom Commands.

To run scripts automatically when an object is selected in a geometry view:

  1. Select File Preferences from the application menu bar.

    The Preferences dialog appears.

  2. Expand the Tools node and click Selection.

  3. Type the command name and any parameters in the Selection Change Command box. For example, in VBScript syntax:

    LogMessage GetValue("SelectionList")

    This setting is stored with your user preferences and is used in all scenes.

NoteThe selection change command is run only when you select something in a 3D view. It is not run when selecting elements in the explorer or schematic views.

To run scripts automatically when the current frame changes

You can select a script or native Softimage command to run automatically after the current frame is changed and the scene is updated. This lets you use scripts to simulate persistent effects.

  1. Select Playback Playback Options from the Playback panel under the timeline.

    The Play Control property editor appears.

  2. Select the Update tab. In the On-Frame-Change Script Command box, enter the command name and any parameters. This setting is stored with the scene.

ImportantThe On-Frame-Change Script Command setting is saved with the scene. If you set it to a custom command, make sure that the custom command is available on all systems used for opening the scene.

Disabling Command Logging Temporarily

You can disable command logging temporarily while your scripts are running. This speeds up the execution of scripts because each command is not logged in the script editor's history pane.

Alternatively, you can disable command logging permanently from the Preferences dialog box. See Disabling and Enabling Command and Message Logging.

NoteDisabling the logging of commands does not affect the ability to undo commands individually. It only affects the logging of commands in the history pane.

To disable command logging temporarily:

The following snippet shows how to get the current preference for command logging, turn logging off, and then restore the preference after running the script.

// Get current state 
var prefs = Application.Preferences;
var originalsetting = prefs.GetPreferenceValue("scripting.cmdlog");

// Disable command logging
if (!originalsetting) { 
	prefs.SetPreferenceValue("scripting.cmdlog", false); 
}

//
// Perform actions
//

// Restore logging setting
prefs.SetPreferenceValue("scripting.cmdlog", originalsetting);
Note

You can also:

  • 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.

Terminating Scripts

To stop execution of a script while it is running, press Ctrl+Break (Ctrl+Pause on some keyboards). You might need to press this key combination a few times because the keyboard is checked only before executing each native Softimage command.

Creative Commons License Except where otherwise noted, this work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License