Looping over an XSICollection

This is a beginner-level walkthrough of a VBScript snippet.

set oColl = CreateObject( "XSI.Collection" )
oColl.Items = "*_face_crv?"

for each oObj in oColl
	LogMessage oObj.fullname 

Line 01: We use the VBScript function CreateObject to create an instance of the ActiveX object XSICollection. XSICollection is a part of the XSI SDK, and is available only inside Softimage.

Line 02: Softimage uses string expressions to reference scene elements. For example, the expression “*_face_crv?” expands to “lf_face_crv1,lf_face_crv2,rf_face_crv1,rf_face_crv2” if you have objects with those names in the scene. The [undocumented] XSICollection.Items property takes a string expression and puts the corresponding objects into the XSICollection.

Line 04: We use the VBScript for each nextstatement to loop over the XSICollection.

Line 05: LogMessage is a method of the Application object, which is part the XSI SDK. FullName is a property available on most objects in Softimage.

Here’s the JScript equivalent, with an additional line of code that uses regex to update the object names.

var oColl = new ActiveXObject( "XSI.Collection" );
oColl.Items = "*_face_crv";

oEnum = new Enumerator( oColl ) ;
for (;!oEnum.atEnd();oEnum.moveNext() )
	var oSelItem = oEnum.item() ;
	LogMessage( oSelItem.fullname );
	oSelItem.Name = oSelItem.Name.replace( /crv/, "loc" );
	LogMessage( oSelItem.fullname );


Further reading: