Using Custom Filters in Code

You can use custom filters in scripting and C++ code, just like any other Softimage filter. For example, you can use custom filters with commands such as PickElement and SIFilter.

var cloList = SIFilter( Application.Selection, "My3DObjectFilter" );

This call to SIFilter fires the My3DObjectFilter_Match callback for each object in the selection list. Softimage takes care of marshalling the objects in the selection to the Context objects expected by the Match callback. Note also that if the selection contains something other than a 3D object, such as polygons or edges, Softimage gets the X3DObject parent and passes it to Match. This is true for 3D object filters only; other filter types will get whatever is in the selection.

Custom filters are included in the Application.Filters collection, so you can use custom filters with the object model:

var oFilter = Application.Filters("MyPolygonFilter");
var cloSubComponents = oFilter.Subset( Application.Selection );

// For each object with selected polygons that matched the filter
for (var objEnum = new Enumerator( cloSubComponents ) ; !objEnum.atEnd(); objEnum.moveNext() )
   var oObject = objEnum.item();

   // Do something with each polygon
   for (var polyEnum = new Enumerator( oObject.SubComponent.ComponentCollection ) ; !polyEnum.atEnd(); polyEnum.moveNext() )
       var oPoly = polyEnum.item();
       // Do something


Note that for Subset, Softimage put the Selection object in the callback context, so Subset gets whatever is selected. The same thing happens if you invoke oFilter.Subset() with a collection of objects: Softimage puts the collection as is in the callback context, and Subset gets whatever is in the collection.

Autodesk Softimage 2011