New in Softimage 2013: Filtering XSICollections


In Softimage 2013, the XSICollection object now has a Filter method, so you can filter XSICollections by type, family, or path name.

oFilteredCollection = XSICollection.Filter( [Type], [Families], [Path] )

I updated my find all cameras script to use XSICollection.Filter, and here’s the timing results (form the same scene, but in 2013).

# INFO : getCameras_FindObjects finished in 0.033000 seconds
# INFO : Found 8301 cameras
# INFO : getCameras_FindObjects_w_Filter finished in 0.269000 seconds
# INFO : Found 24 cameras
# INFO : getCameras_FindObjects_w_SIFilter finished in 0.044000 seconds
# INFO : Found 24 cameras
# INFO : getCameras_FindObjects2 finished in 0.001000 seconds
# INFO : Found 49 cameras
# INFO : getCameras_FindObjects2_w_Filter finished in 0.003000 seconds
# INFO : Found 24 cameras
# INFO : getCameras_FindChildren2 finished in 0.149000 seconds
# INFO : Found 24 cameras
# INFO : getCameras_SelectAllUsingFilter finished in 0.035000 seconds
# INFO : Found 24 cameras
  • FindObjects2 is fastest, with SelectAllUsingFilter a mildly surprising second (again note that I’m calling SelectAllUsingFilter with AffectSelectionList=False, so I’m not actually selecting anything).
    FindObjects2_w_Filter		0.003000 seconds
    SelectAllUsingFilter		0.035000 seconds
    FindObjects_w_SIFilter		0.044000 seconds
    FindChildren2			0.149000 seconds
    FindObjects_w_Filter		0.269000 seconds
    
  • FindObjects finds a lot more than just cameras; it finds lots of nulls too because that GUID isn’t unique to cameras
  • In this context, SIFilter is faster than the XSICollection.Filter method

Here’s the updated script for Softimage 2013:

import time
si = Application
log = si.LogMessage
from win32com.client import constants as C

import win32com.client
oCameraColl = win32com.client.Dispatch( "XSI.Collection" )

si.SetValue("preferences.scripting.cmdlog", False, "")


def timeExecution(func):
    def closure(*args, **kwargs):
        startTime = time.time()
        try:
            ret = func(*args, **kwargs)
        except Exception, e:
            delta = time.time() - startTime
            log('Failed in %f seconds' % delta)
            raise
        delta = time.time() - startTime
        log('%s finished in %f seconds' % (func.__name__, delta))
        return ret
    return closure 

@timeExecution
def getCameras_FindObjects():
	oCameraColl = Application.FindObjects( "", "{5FC0CCAE-3DC8-11D0-9449-00AA006D3165}" )
	return oCameraColl.Count

@timeExecution
def getCameras_FindObjects_w_Filter():
	oCameraColl = Application.FindObjects( "", "{5FC0CCAE-3DC8-11D0-9449-00AA006D3165}" )
	oCameraColl = oCameraColl.Filter( "camera" )
	oCameraColl.RemoveItems( oCameraColl.Filter( "", "", "CopyPaste*" ) )
	oCameraColl.RemoveItems( oCameraColl.Filter( "", "", "View*" ) )
	return oCameraColl.Count

@timeExecution
def getCameras_FindObjects_w_SIFilter():
	oCameraColl = Application.FindObjects( "", "{5FC0CCAE-3DC8-11D0-9449-00AA006D3165}" )
	oCameraColl = si.SIFilter( oCameraColl, "camera" )
	oCameraColl.RemoveItems( oCameraColl.Filter( "", "", "CopyPaste*" ) )
	oCameraColl.RemoveItems( oCameraColl.Filter( "", "", "View*" ) )
	return oCameraColl.Count


@timeExecution
def getCameras_FindObjects2():
	c = si.FindObjects2( C.siCameraID )
	return c.Count

@timeExecution
def getCameras_FindObjects2_w_Filter():
	cams = si.FindObjects2( C.siCameraID )
	oCameraColl.Items = cams
	oCameraColl.RemoveItems( cams.Filter( "", "", "CopyPaste*" ) )
	oCameraColl.RemoveItems( cams.Filter( "", "", "View*" ) )
	return oCameraColl.Count


@timeExecution
def getCameras_FindChildren2():
	cams = si.ActiveSceneRoot.FindChildren2("", "camera")
	return cams.Count

@timeExecution
def getCameras_SelectAllUsingFilter():
	cams = si.SelectAllUsingFilter("Camera", "siIgnoreComponentVisibility", False, "")
	return cams.Count



@timeExecution
def getCameras_Model_FindObjects():
	cams = si.ActiveSceneRoot.FindObjects( C.siCameraID )
	return cams.Count


log( 'Found %d cameras' % getCameras_FindObjects() )
log( 'Found %d cameras' % getCameras_FindObjects_w_Filter() )
log( 'Found %d cameras' % getCameras_FindObjects_w_SIFilter() )
log( 'Found %d cameras' % getCameras_FindObjects2() )
log( 'Found %d cameras' % getCameras_FindObjects2_w_Filter() )
log( 'Found %d cameras' % getCameras_FindChildren2() )
log( 'Found %d cameras' % getCameras_SelectAllUsingFilter() )

Filtering object selection by volume


Here’s an addon that uses the ICE Volume attribute to filter object selections. The Volume attribute is always defined (so you don’t need to Show Values or anything for this filter to work).

Note that you have to freeze scaling to get the right volume for an object.

For simplicity, I’m using a custom property (on the scene root) to hold the preferences for the filter.

The filter itself is simple. It just gets the Volume attribute value and compares it to the range of values specified in the PPG.

# Match callback for the psCustomFilters custom filter.
def ObjbyVolume_Match( in_ctxt ):
	Application.LogMessage("ObjbyVolume_Match called",constants.siVerbose)

	in_object = in_ctxt.GetAttribute( "Input" );

	obj = Get3DObject( in_object );
	if ( Application.ClassName(obj) != "X3DObject" ):
		return false;
	
	v = obj.ActivePrimitive.ICEAttributes("Volume").DataArray[0]

	filterProp = GetFilterProp( )
	if filterProp.Filter_by_range.Value == True:
		bMatch = filterProp.Volume_Min.Value <= v <= filterProp.Volume_Max.Value
	else: # Filter by value with an epsilon
		min = filterProp.Value.Value - filterProp.Epsilon.Value
		max = filterProp.Value.Value + filterProp.Epsilon.Value
		bMatch = min <= v <= max
		
	return bMatch