Softimage SDK Programmer's Guide > Script Development > Using the Script Editor >

# Running Scripts

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.

- Note that scripts can no longer change the number of undo levels permanently. This prevents problems that occured when scripts set the number of undo levels to 0 to increase performance, and then failed to set it back or terminated abnormally.

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.

To run a script from the script editor

Do one of the following:

- Click Run on the command bar.

  or

- Press F5.

  or

- Choose Edit Run from the command bar.

  or

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

Running Parts of Scripts

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:

- 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 as described in Custom Commands.

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

1. Choose File User Preferences from the Autodesk Softimage main menu.

   The User Preferences dialog box opens.

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

Note

The OnSelectionChange 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 Autodesk 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. Choose Playback Playback Options from the Playback panel below the timeline.

   The Play Control property editor opens.

2. Click 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.

Important

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

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.

Note

Disabling the logging of commands has no effect on the ability to undo commands individually. It affects only whether commands are echoed to the history pane of the script editor.

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 );

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 for more details.

Terminating Scripts

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.

Important

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.