ObjectIDs and objects that don’t exist


As noted by iamVFX on si-community, the new Python method Application.GetObjectFromID2 doesn’t deal well with IDs that don’t match an object that exists in the scene (in fact, it crashes Softimage). The JScript version, Application.GetObjectFromID simply returns null in that situation.

So, it is probably best to use DataRepository.HasData to check if the ID represents a real object.

Note that Dictionary.GetObject can also be used to get objects by ID.

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


MAX_IDS = 2000

for i in range(0,MAX_IDS):
	if XSIUtils.DataRepository.HasData( i ):
		try:
			o =  si.GetObjectFromID2( i )
			log( "%s : %s" % (str(i), o.FullName) )
		except:
			o = Application.Dictionary.GetObject( "object<%s>" % str(i) )
			s = "%s : GetObjectFromID2 failed. Dictionary.GetObject found %s (%s)" % (str(i), o.Name, si.ClassName(o))
			log( s )
	else:
		log( "%s : No object with this ID exists" % str(i) )

A new, blank Softimage 2013 scene has 757 objects. For your reading pleasure, the full list is below the fold.
Continue reading