Using XSICollections to check for character key sets


The IsCharacterKeySet parameter is not [directly] exposed through the Object Model, so you can’t get at the parameter through the Parameters or even NestedObjects. Instead, you can access the IsCharacterKeySet parameter with the GetValue and SetValue commands.

XSICollection does, however, provide an Object Model way to get at the parameter:

LogMessage( isCharKeySet( Selection(0) ) );

function isCharKeySet( o )
{
	var oColl = new ActiveXObject( "XSI.Collection" );
	oColl.items = o.FullName + ".IsCharacterKeySet";
	return ( oColl(0) != null && oColl(0).Value == true );
}

WARNING – Unknown flag (ignored) : -processing


When you use the -processing flag, you can ignore the “Unknown flag” warning. As long as you see “License information: using [Processing]”, you know that xsibatch is using one of the unlimited processing licenses.

C:\Softimage\Softimage_2010_x64\Application\bin>xsibatch -processing-script hello.js
=======================================================
 Autodesk Softimage 8.0.201.0
=======================================================
        
License information: using [Processing]
        COMMAND: -processing -script hello.js
WARNING - Unknown flag (ignored) : -processing
# INFO : Hello World

Creating tabs in the Material Manager


The new AddUserTab command allows you to create new custom favorites tabs in the Material Manager. To use AddUserTab, you pass in a material and a comma-separated list of tab names.

var oActiveScene = Application.ActiveProject.ActiveScene;
var oMatLib = oActiveScene.ActiveMaterialLibrary;
var oMat = oMatLib.CreateMaterial( "Phong", "MyPhong" );

AddUserTab( oMat, "My Faves" );

SUMATRAPATH


SUMATRAPATH is an environment variable that is defined only in Softimage. SUMATRAPATH points to the Application\bin folder in the Softimage folder, and the registry is full of Softimage entries that use SUMATRAPATH to specify the location of DLLs.

In XSI 7.01, you could check whether or not you were in Softimage with this Python code:

import os
app = Application
if os.getenv( ‘SUMATRAPATH’ ) != None :
        app.LogMessage( “you’re in XSI” )
else:
        app.LogMessage( “you’re not in XSI” )

However, in both Softimage 7.5 and 2010, os.getenv(“SUMATRAPATH”) returns None. At least for me it does.

XSIUtils.Environment.Item(“SUMATRAPATH”) does still return the Application\bin path, as does this Jscript:

var oShell = new ActiveXObject ("WScript.Shell");
var oProcessEnv = oShell.Environment("Process");
LogMessage( oProcessEnv( "SUMATRAPATH" ) );

Sumatra was the original code name for the product that eventually became known as Softimage XSI (the Softimage XSI name was unveiled back in March 2000).

Turning on mental ray diagnostics from the command line


In Softimage, you can enable the diagnostics in the Render Manager, by going to the Diagnostics tab and selecting the Information and Progress check boxes. If you’re working on the command-line with xsibatch, you may not want to start up Softimage just to select those check boxes. So, here’s how to do from the command line: just add -script and -verbose “on” to the xsibatch command line.


xsibatch -render "\\server\project\Scenes\Example.scn" -frames 1 -script verbosity.js -verbose "on"

where verbosity.js is a script that looks like this:

// Information and Progress
Dictionary.GetObject("Passes.mentalray").Parameters("VerbosityLevel").Value = 60;

If you set the VerbosityLevel to 252, you will get the Basic and Detailed Debug log messages too.

xsibatch -script -render


By combining -script and -render, you can use a script to set up a scene for rendering. xsibatch loads the scene, runs the script, and then does the render.
Any changes made by the script are not saved.

You can also use -script with -export flag. For example, if you wanted to change the output folder for .mi files, you could do this:

xsibatch -processing -export \\server\share\xsiDB\Scenes\test.scn
-script tmpChangeOutputDir.js -frames 1-5 -pass all

where the .js file changes Passes.RenderOptions.OutputDir to the desired output location.

Where does PPG come from?


In property page callbacks like OnClicked and OnChanged, you can use the PPG object to access the parameters on the property page. For example:

def TestProp_text_OnChanged():
Application.LogMessage(PPG.text.Value)

The docs say that PPG is a global variable, but if you try to use PPG outside of a callback, you’ll get a “name is not defined” error.
Or, if you try to put all your callbacks into a separate module, you’ll get that “name is not defined” error again. Several XSI users have hit this problem:

Subject : Re: PPG in self-installable plugins
Interpreter global?
If you just start the script editor and type:

Application.LogMessage(str(PPG))

You’ll get:

#NameError: name 'PPG' is not defined

But in the aforementioned callback if you do:
def TestProp_text_OnChanged( ):
if 'PPG' in globals():
log('Yehaw!')

It’ll find PPG in the globals. When did it get there and how? And more importantly who’s globals?

globals() is module specific (Dive into Python, 8.5 – locals and globals) so if I define a decorator in a separate module it can’t access the global PPG that lives in the global namespace of my plugin.

Arrggsjabcsjdbhcsd!!! My brain is turning to mush!

So what’s up with this PPG object? Where does it come from, and why can’t you access it when you put the callback function into a module?

The answer is that the callback is executed in its own instance of the scripting engine, with its own namespace.
To execute the callback, XSI creates a script engine for the logic (aka the ppg callbacks), and inserts the PPG object into the scripting engine namespace.

When I answered this question back in 2005 on the XSI list, I was officially named one of the ten coolest people in the Universe :-).