Your Ad Here

Batch Scripts

You can run scripts in batch mode from a shell or command prompt window, without invoking the interface. This is also known as command line scripting. You can specify the procedure to run, as well as supply any necessary arguments. Before running a script in batch mode, you may need to first prepare it.

 

In batch mode, the command history is logged to the standard output stdout. If desired, you can also log it to file as described in The Command Log

Preparing Scripts for Batch Mode

In batch mode, scripts cannot require any interactive input such as prompting for a file or path — this does not include property editors that open automatically as you work in the interface. For example, the following code would generate an error if it is run in batch mode. This is because the OpenScene command, when invoked without any arguments, displays a dialog box that prompts for a scene to import.

   sub MyBatchScript()
   OpenScene                       ' error
end sub

' Main
MyBatchScript

There are two ways to deal with this. The first way is to explicitly provide all arguments in the script. For example:

OpenScene "C:\MyProject\MyScene.scn", false

In this case, the false argument is a flag that indicates that there should be no prompt to save changes to the current scene. There is a similar flag for DeleteAll.

The other way is to declare any necessary parameters as arguments in a procedure declaration and then pass them on the command line when the script is run in batch mode. For example, in VBScript you would declare the arguments for a procedure as follows:

   Sub myproc(myargname1, myargname2)
   ...
End Sub

At a command prompt, you would then run the script as shown below (it should all be on one line):

xsi -script myscriptfile.vbs -main myproc 
    -args -myargname1 myargvalue1
           -myargname2 myargvalue2

How to check in which mode (batch or interactive) XSI is running

You can use the Interactive property on the Application object to find out whether XSI is running in interactive mode (returns True) or in batch mode (returns False):

' Using Application.Interactive is the same as Application.Interactive = True
If Application.Interactive Then
   Application.LogMessage "The application is running in interactive mode."
Else
   Application.LogMessage "The application is running in batch mode."
End If

Running Scripts in Batch Mode

To run a script in batch mode, you must set the environment and then start XSI with the script.

Setting the Environment

Before running a script in batch mode, you should first set the environment properly:

• On Windows, open a command prompt.

To do this, choose All Programs > Softimage Products > SOFTIMAGE|XSI 6.01 > Command Prompt from the Windows Start menu.

• On Linux, open a shell and source the .xsi_6.01 XSI resource file.

Launching XSI with a Script

To run the program and a script in batch mode, start XSI with the -script switch, specifying your script file name. There are several ways to do this, depending on whether you need to specify the scripting language, specify the procedure to run, or supply values for arguments.

If you need the script to run in the XSI user interface, for example, to perform hardware rendering, use -uiscript instead of -script.

To run simple scripts in batch mode

To run a simple VBScript file named myscript.vbs, use the following syntax at the command prompt:

xsi -script myscript.vbs

If there is a space in the path or file name, enclose the complete path in double quotes, for example:

xsi -script "\My Files\myscript.vbs"

To specify the scripting language in batch mode

The scripting language is determined by the file name extension according to information in the registry: by default, this is .vbs for VBScript, .js for JScript, .pls for PerlScript, and .pys for Python.

If your script file uses a different extension, you can specify the language explicitly with the -lang switch. For example, to run a script file named myscript.xxx, use one of the commands below:

xsi -script myscript.xxx -lang VBScript
xsi -script myscript.xxx -lang JScript
xsi -script myscript.xxx -lang PerlScript
xsi -script myscript.xxx -lang Python

To specify a procedure in batch mode

By default, when you run a script in batch mode, only global code is executed. If your script contains procedures, you can use the -main switch to specify which procedure to run. For example, to run a procedure named myproc in a VBScript file named myscript.vbs, use the following syntax:

xsi -script myscript.vbs -main myproc

 

Even when a procedure is specified, global code may be executed before the procedure is called. This is a side effect of parsing the script with some scripting engines. To be certain that your script behaves predictably in all situations, do not mix global code and procedures.

To supply arguments in batch mode

If your procedure requires arguments, you can specify them after the -args switch. For example, if the procedure myproc in myscript.vbs requires two arguments named myargname1 and myargname2, you can run the procedure and set the argument values with the following syntax (it should all be on one line):

xsi -script myscript.vbs -main myproc 
-args -myargname1 myargvalue1 -myargname2 myargvalue2

 

• If you specify arguments with the -args switch but do not specify a procedure with the -main switch, XSI looks for a procedure called main and runs it. If there is no procedure called main, global code is executed and the command line arguments are ignored.

• XSI cannot pass arguments to scripts written in Perl in batch mode. For these languages, you can write a second script that calls the appropriate procedure using the desired argument values.

Running Scripts Remotely

You can run XSI in batch mode remotely using Telnet or a remote shell (rsh):

• On Linux, use xsi -script or xsi -R as usual.

• On Windows, use xsibatch -script or xsibatch -R instead.

The xsibatch command supports the same options as xsi. However, the beta version of the Telnet daemon included in some versions of the Windows Resource Kit (TELNETD) is not supported.

Automatically Closing the Command Window

By default in batch mode on Windows, XSI runs in a new window that stays open after the process is finished. This allows you to see any messages that have been logged to the console.

However, it is sometimes desirable to turn this behavior off. For example, you may want to automatically run several scripts one after another from a single batch file. If the new window does not close, control does not return to the original batch process and the next script cannot start.

To make the command window close automatically, do either of the following:

• Use xsibatch as described in the previous section.

or

• Use xsi with the -continue option in the command line that starts XSI:

xsi -continue -script myscript.vbs

When started with this option, the new window closes automatically when the process terminates. The script or batch file that started XSI can then continue processing.

Real-Time Message Logging

When running scripts, you can set your preferences to allow for real-time message logging. This is particularly useful when rendering in batch mode. To activate real-time message logging:

1. Open the Preferences window by choosing File > Preferences from the main menu.

2. Click Scripting.

3. Set the Real-Time Message Logging option as you want it:

- When this option is off (default), commands that involve picking sessions are properly logged after all the inputs have been picked.

- When this option is on, messages are logged as they occur. This lets you see, for example, messages about each frame as it is rendered rather than after all frames are rendered.

You can also get and set this preference using the "RealTimeMessageLogging" string and the GetUserPref and SetUserPref commands.

For example, the following VBScript script stores the current preference, then activates real-time message logging, renders the current pass, and finally restores the original preference:

Dim flag
flag = GetUserPref("RealTimeMessageLogging")
SetUserPref "RealTimeMessageLogging", True
RenderPass
SetUserPref "RealTimeMessageLogging", flag


SOFTIMAGE|XSI v.6.01     

Return to Softimage XSI Index


Your Ad Here