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
	from win32com.client import Dispatch as disp
	from win32com.client import constants as C
	log = disp('XSI.Application').LogMessage
except ImportError: # pywin not installed
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)
            set out_objs = oObjectList
        end if

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s