Troubleshooting 101: Startup Crashes


Here’s the basic recipe for troubleshooting a startup crash:

See also:

Saturday snippet: Converting strings to objects


XSICollections know how to handle (aka parse) string expressions like ‘cube.pnt[2,4,LAST]’

si = Application
import win32com.client
c = win32com.client.Dispatch( "XSI.Collection" )

#c.SetAsText( 'cube.pnt[2,4,LAST]' )
c.Items = 'cube.pnt[2,4,LAST]'

print c.Count
print si.ClassName( c(0) )
print c(0).SubComponent.ComponentCollection.Count
print si.ClassName( c(0).SubComponent.ComponentCollection(0) )
print c(0).SubComponent.ComponentCollection(2).Index
# 1
# CollectionItem
# 3
# Vertex
# 7

Back in 1999, this code looked something like this:

CreatePrim "Cube", "MeshSurface"
set list = GetCollection( "cube.pnt[2,3,6,LAST]" )

if not typename(list) = "Nothing" then
	logmessage list
end if

function GetCollection( in_str )
	Dim l_myList 

	set GetCollection = CreateObject( "Sumatra.Collection" )

	On Error Resume Next
	GetCollection.items = in_str

	if GetCollection.Count = 0 then
		set GetCollection = Nothing
	end if

end function

Saturday snippet: XSICollection has no class


Calling Application.ClassName() on an XSICollection object returns “Object”, not the class name. Remember this when you’re using ClassName() to check what type of object is being handled in some piece of script.

# See http://docs.python.org/2/tutorial/errors.html#handling-exceptions
try:
	from win32com.client import Dispatch as disp
	from win32com.client import constants as C
	log = disp('XSI.Application').LogMessage
except ImportError: # pywin not installed
	pass
	
si = disp('XSI.Application') 
x = disp( "XSI.Collection" )

log( si.ClassName( x ) )

# INFO : Object

A long time ago, it was decided not to fix this, because the fix would break existing scripts. Back in those old days, the VBScript function TypeName() was used instead of Application.ClassName(), so you had a fair amount of VBScript that was checking whether TypeName() returned “Object”. (Calling TypeName() on most Softimage objects returns the class name)

You can see an example of this type [haha!] of thing in Application\DSScripts\animation.vbs:

        if TypeName( oObjectList ) = "Object" then
            set out_objs = oObjectList.Item(0)
        else
            set out_objs = oObjectList
        end if