TrackCollection.Filter.3.js Example

Applies To

TrackCollection.Filter method

Description

This example demonstrates how to use the TrackCollection.Filter method.

Code

/* --------------------------------------------------------------
	This example demonstrates how to combine the parameters of 
	the Filter method to fine-tune the search criteria
*/
// Build a new scene with lots of objects to filter and return the scene root
var child_coll = CreateScene().Children;
// Using this criterion will match either nulls or srfmesh elements
families2find = new Array( "Nurbs Surface Mesh Geometries", "Nulls" )
WriteCollection( child_coll.Filter( "", "","*Cone" ), 
	"filter( , ,'*Cone' )", "any item with a name ending in 'Cone'" );
WriteCollection( child_coll.Filter( "", "","MyAwesome*" ), 
	"filter( '', '', '*Awesome*' )", "any item with a name starting with 'MyAwesome'" );
WriteCollection( child_coll.Filter( "Cone", families2find,"MyAwesome*" ), 
	"filter( 'Cone', new Array( 'Nurbs Surface Mesh Geometries', 'Nulls' ), 'MyAwesome*' )",
	"any cone with a name starting with 'MyAwesome' that is either a surfmsh or a null" );
WriteCollection( child_coll.Filter( "Cone", families2find ), 
	"filter( 'Cone', new Array( 'Nurbs Surface Mesh Geometries', 'Nulls' ) )",
	"any cone that is either a surfmsh or a null" );
WriteCollection( child_coll.Filter( "", families2find ), 
	"filter( '', Array( 'Nurbs Surface Mesh Geometries', 'Nulls' ) )",
	"any item that is either a surfmsh or a null"  );
WriteCollection( child_coll.Filter( "Cone", "Nurbs Surface Mesh Geometries" ), 
	"filter( 'Cone', 'Nurbs Surface Mesh Geometries' )",
	"any surfmsh cone"  );
WriteCollection( child_coll.Filter( "Cone" ), 
	"filter( 'Cone' )", "any cone"  );
WriteCollection( child_coll.Filter( "Torus", "","*Super*" ), 
	"filter( 'Torus', '', '*Super*' )", 
	"any torus with a name containing 'Super'"  );
WriteCollection( child_coll.Filter( "", "Nurbs Surface Mesh Geometries" ), 
	"filter( '', 'Nurbs Surface Mesh Geometries' )", 
	"any surfmsh" );
WriteCollection( child_coll.Filter( "", "Mesh Geometries" ), 
	"filter( '', Mesh Geometries )", "any polymsh"   );
WriteCollection( child_coll.Filter( "", "Mesh Geometries","*Cone" ), 
	"filter( '', 'Mesh Geometries', '*Cone' )", 
	"any polymsh item with a name ending in 'Cone'" );

/* --------------------------------------------------------------
	This function adds the following items to the scene root:
	Name                Primitive Type      Geometry Type
	---------------     --------------      -------------
	MySuperCone         polymsh             Cone
	MySuperCylinder     polymsh             Cylinder
	MyAwesomeCone       surfmsh             Cone
	MyAwesomeTorus      polymsh             Torus
	MySuperTorus        surfmsh             Torus
	MyImplicitCube      cube                Cube
	MyAwesomeNull       --                  Null
	CameraRoot          --                  CameraRig
	camera1             --                  Camera
	CameraInterest      --                  Null
*/
function CreateScene()
{
	NewScene( null, false );
	var root = ActiveProject.ActiveScene.Root;
	root.AddGeometry( "cone", "meshsurface", "MySuperCone" );
	root.AddGeometry( "Cylinder", "meshsurface", "MySuperCylinder" );
	root.AddGeometry( "cone", "nurbssurface", "MyAwesomeCone" );
	root.AddGeometry( "Torus", "nurbssurface", "MySuperTorus" );
	root.AddGeometry( "Torus", "meshsurface", "MyAwesomeTorus" );
	root.AddPrimitive( "cube", "MyImplicitCube" );
	root.AddNull( "MyAwesomeNull" );
	root.AddCameraRig( "Camera" );
	return root;
}
/* --------------------------------------------------------------
	This function prints the collection information
*/
function WriteCollection( in_collection, in_filter_text, in_plain_text )
{
	// Make sure the script doesn't break
	try {
		LogMessage( "-----" );
		LogMessage( "TEST: " + in_filter_text );
		LogMessage( "      [" + in_plain_text + "]" );
		LogMessage( "Size of collection: " + in_collection.Count );
		for ( var i=0; i<in_collection.Count; i++ ) {
			LogMessage( "\titem #" + (i+1) + ": " + in_collection(i).Name 
				+ " (type = " + in_collection(i).Type + ")" );
		}
		return 1;
	} catch(e) {
		LogMessage( "Encountered a problem with the input collection. Quitting..." );
		return 0;
	}
}

/* --------------------------------------------------------------
	Output of the above script:
*/
//INFO : -----
//INFO : TEST: filter( , ,'*Cone' )
//INFO :       [any item with a name ending in 'Cone']
//INFO : Size of collection: 2
//INFO : 	item #1: MySuperCone (type = polymsh)
//INFO : 	item #2: MyAwesomeCone (type = surfmsh)
//INFO : -----
//INFO : TEST: filter( '', '', '*Awesome*' )
//INFO :       [any item with a name starting with 'MyAwesome']
//INFO : Size of collection: 3
//INFO : 	item #1: MyAwesomeCone (type = surfmsh)
//INFO : 	item #2: MyAwesomeTorus (type = polymsh)
//INFO : 	item #3: MyAwesomeNull (type = null)
//INFO : -----
//INFO : TEST: filter( 'Cone', new Array( 'Nurbs Surface Mesh Geometries', 'Nulls' ), 'MyAwesome*' )
//INFO :       [any cone with a name starting with 'MyAwesome' that is either a surfmsh or a null]
//INFO : Size of collection: 1
//INFO : 	item #1: MyAwesomeCone (type = surfmsh)
//INFO : -----
//INFO : TEST: filter( 'Cone', new Array( 'Nurbs Surface Mesh Geometries', 'Nulls' ) )
//INFO :       [any cone that is either a surfmsh or a null]
//INFO : Size of collection: 1
//INFO : 	item #1: MyAwesomeCone (type = surfmsh)
//INFO : -----
//INFO : TEST: filter( '', Array( 'Nurbs Surface Mesh Geometries', 'Nulls' ) )
//INFO :       [any item that is either a surfmsh or a null]
//INFO : Size of collection: 5
//INFO : 	item #1: Camera_Root (type = CameraRoot)
//INFO : 	item #2: MyAwesomeCone (type = surfmsh)
//INFO : 	item #3: MySuperTorus (type = surfmsh)
//INFO : 	item #4: MyAwesomeNull (type = null)
//INFO : 	item #5: CameraRoot (type = CameraRoot)
//INFO : -----
//INFO : TEST: filter( 'Cone', 'Nurbs Surface Mesh Geometries' )
//INFO :       [any surfmsh cone]
//INFO : Size of collection: 1
//INFO : 	item #1: MyAwesomeCone (type = surfmsh)
//INFO : -----
//INFO : TEST: filter( 'Cone' )
//INFO :       [any cone]
//INFO : Size of collection: 2
//INFO : 	item #1: MySuperCone (type = polymsh)
//INFO : 	item #2: MyAwesomeCone (type = surfmsh)
//INFO : -----
//INFO : TEST: filter( 'Torus', '', '*Super*' )
//INFO :       [any torus with a name containing 'Super']
//INFO : Size of collection: 1
//INFO : 	item #1: MySuperTorus (type = surfmsh)
//INFO : -----
//INFO : TEST: filter( '', 'Nurbs Surface Mesh Geometries' )
//INFO :       [any surfmsh]
//INFO : Size of collection: 2
//INFO : 	item #1: MyAwesomeCone (type = surfmsh)
//INFO : 	item #2: MySuperTorus (type = surfmsh)
//INFO : -----
//INFO : TEST: filter( '', Mesh Geometries )
//INFO :       [any polymsh]
//INFO : Size of collection: 3
//INFO : 	item #1: MySuperCone (type = polymsh)
//INFO : 	item #2: MySuperCylinder (type = polymsh)
//INFO : 	item #3: MyAwesomeTorus (type = polymsh)
//INFO : -----
//INFO : TEST: filter( '', 'Mesh Geometries', '*Cone' )
//INFO :       [any polymsh item with a name ending in 'Cone']
//INFO : Size of collection: 1
//INFO : 	item #1: MySuperCone (type = polymsh)

Related Examples

TrackCollection.Filter.2.pys

TrackCollection.Filter.4.pys

TrackCollection.Filter.1.vbs

Keywords

TrackCollection Filter


Autodesk Softimage 2011