Dispatching XSI.Factory versus using the intrinsic XSIFactory object


The other day in the comments, A asked about some Python I had posted a few years ago: Why did I manually dispatch XSI.Factory instead of just using the global XSIFactory object? Honestly, I don’t know why I did. I had seen other code do it that way, so I did it too. And I see that the sipyutils.py also dispatches objects like XSI.Application, XSI.Utils, and XSI.Math, so I figured I was in good company.

A little research shows that XSIFactory uses late bound automation (aka dynamic dispatch) and so avoids any possible problems with the pywin32 cache. Late-bound automation means that PythonCOM doesn’t know what properties or methods the object supports; whenever you try to access a property or method, PythonCOM will query the object to find out if the property/method is supported.

In contrast, when you dispatch XSI.Factory, PythonCOM uses the pywin32 cache to support early-binding, where all the available properties and methods are known beforehand.

You can read more about this Chapter 12 of Python Programming on Win32, Advanced Python and COM

Here’s a little Python snippet demonstrating the differences between a dispatched XSI.Factory and the global XSIFactory object. Note in particular the output of dir() for each object.

from win32com.client import Dispatch as disp
sifact = disp('XSI.Factory')

print sifact
print XSIFactory
# <win32com.gen_py.Softimage|XSI Object Model Library v1.5.XSIFactory instance at 0x564246344>
# <COMObject XSIFactory>

print dir(sifact)
print dir(XSIFactory)
# ['CLSID', 'CreateActiveXObject', 'CreateFCurveKeyCollection', 'CreateFCurveParamDef', 'CreateGridData', 'CreateGridParamDef', 'CreateGuid', 'CreateObject', 'CreateObjectFromFile', 'CreateObjectFromFile2', 'CreateObjectFromPreset', 'CreateObjectFromPreset2', 'CreateParamDef', 'CreateParamDef2', 'CreateScriptedOp', 'CreateScriptedOpFromFile', 'CreateShaderDef', 'CreateShaderParamDefOptions', 'RemoveShaderDef', '_ApplyTypes_', '__doc__', '__eq__', '__getattr__', '__init__', '__module__', '__ne__', '__repr__', '__setattr__', '_get_good_object_', '_get_good_single_object_', '_oleobj_', '_prop_map_get_', '_prop_map_put_', 'coclass_clsid']
# ['_Close_', '__doc__', '__getattr__', '__init__', '__module__', '__repr__', '__setattr__', '_scriptItem_']

print sifact.__module__
print XSIFactory.__module__
# win32com.gen_py.269C4D8C-E32D-11D3-811D-00A0C9AC19A9x0x1x0.XSIFactory
# win32com.axscript.client.pyscript

Why you cannot use shortcuts to access the ViewportCapture settings


In the comments, G asks:

Why do you have do this:

si = Application
oViewportCapture = si.Dictionary.GetObject( "ViewportCapture" )
oViewportCapture.NestedObjects( "Start" ) = 10

and not this:

si = Application
oViewportCapture = si.Dictionary.GetObject( "ViewportCapture" )
oViewportCapture.Start = 10

CaptureOptions
The answer is that the ViewportCapture object is not a ProjectItem, and so does not support the Parameters property. ViewportCapture is a CollectionItemLegacy object (and before that, it was an SIObject).

si = Application
p = si.Dictionary.GetObject( "ViewportCapture.Start" )
p.Value = 10
#si.SetValue( "ViewportCapture.Start", 10 )

Using environment variables in .wkg files


I couldn’t find this in the docs anywhere, but I did find it mentioned in some old emails. You can use environment variables in the .wkg file, like this:

$SITOA_WKG_PATH
$MOOTZOID_WKG_PATH

or this:

${SITOA_WKG_PATH}
${MOOTZOID_WKG_PATH}

Either syntax worked for me when I tried it.

There does seem to be some weirdness with loading workgroup shaders this way, but that’s still under investigation.

Scripting – Creating an empty polygon mesh


There’s several ways to create an empty polygon mesh with the Object Model.

from sipyutils import si			# win32com.client.Dispatch('XSI.Application')
from sipyutils import log		# LogMessage
from sipyutils import C			# win32com.client.constants

si = si()
o = si.Selection(0)

if o.IsClassOf( C.siX3DObjectID ):
	o.AddPolygonMesh()
	o.AddPrimitive( "EmptyPolygonMesh"  )
	o.AddGeometry( "EmptyPolygonMesh" )

AddPolygonMesh() courtesy of Vladimir

Some pricing info from the Autodesk Store


Note: Autodesk store prices are always for Standalone licenses. Network licenses are usually about $750 USD more. Also, when comparing Subscription, make sure you are comparing the same levels of Subscription.

Softimage versus Maya. Softimage is cheaper, but if you go for Subscription, it always includes Advanced Support (which costs extra). The store offers only the slightly cheaper Basic Support for Maya Subscription (but you can buy Advanced Support for Maya).
autodesk_store_soft_maya

Suite pricing. For the Ultimate Suite, you have to take Advanced Support.
autodesk_store_suites

Current Softimage upgrade promotion:
autodesk_store_soft_upgrade