TrackCollection.Filter.4.pys Example

Applies To

TrackCollection.Filter method

Description

This example uses the Path argument of the PropertyCollection.Filter method to find Properties based on their names. Helper function for displaying contents of a PropertyCollection

Code

def WriteCollection( in_collection, in_filter_text, in_plain_text ) :
	Application.LogMessage( "-----" )
	Application.LogMessage( "TEST: " + in_filter_text )
	Application.LogMessage( "      [" + in_plain_text + "]" )
	Application.LogMessage( "Size of collection: " + str(in_collection.Count) )
	for oProp in in_collection:
		Application.LogMessage( "\titem #" + ": " + oProp.FullName 
			+ " (type = " + oProp.Type + ")" )

# Build a sample scene
Application.NewScene( "", 0 )
oModel = Application.ActiveSceneRoot.AddModel( None, "PropModel" )
oNull = oModel.AddNull( "NullWithProps" )
# Add a whole lot of properties
oNull.AddProperty( "CustomProperty", 0, "Prop1" ) ;
oNull.AddProperty( "CustomProperty", 0, "Prop2" ) ;
oNull.AddProperty( "CustomProperty", 0, "Prop3" ) ;
oNull.AddProperty( "CustomProperty", 0, "MyProp" ) ;
oNull.AddProperty( "CustomProperty", 0, "Other" ) ;
oNull.AddProperty( "CustomProperty", 0, "PROP4" ) ;

#
# 	Demonstrate the Filter method:
#
# Filtering by Object Name works based on the FullName of the property
WriteCollection( oNull.Properties.Filter( "","","PropModel.NullWithProps.Prop*" ), 
	"Filter(,,\"PropModel.NullWithProps.Prop*\")", 
	"All Properties under the Null starting with Prop" ) ;
WriteCollection( oNull.Properties.Filter( "","","PropModel.NullWithProps.*Prop*" ), 
	"Filter(,,\"PropModel.NullWithProps.*Prop*\")", 
	"All Properties under the Null containing Prop" ) ;
# Because the matching is done by the full name, we might accidentally match 
# with other properties because the Model and Null also have "Prop" in their names
WriteCollection( oNull.Properties.Filter( "","","*Prop*" ), 
	"Filter(,,\"*Prop*\")", 
	"Properties under the Null with Prop somewhere in the FullName" ) ;

# Expected Results:
#INFO : -----
#INFO : TEST: Filter(,,"PropModel.NullWithProps.Prop*")
#INFO :       [All Properties under the Null starting with Prop]
#INFO : Size of collection: 4
#INFO : 	item #: PropModel.NullWithProps.Prop1 (type = customparamset)
#INFO : 	item #: PropModel.NullWithProps.Prop2 (type = customparamset)
#INFO : 	item #: PropModel.NullWithProps.Prop3 (type = customparamset)
#INFO : 	item #: PropModel.NullWithProps.PROP4 (type = customparamset)
#INFO : -----
#INFO : TEST: Filter(,,"PropModel.NullWithProps.*Prop*")
#INFO :       [All Properties under the Null containing Prop]
#INFO : Size of collection: 5
#INFO : 	item #: PropModel.NullWithProps.Prop1 (type = customparamset)
#INFO : 	item #: PropModel.NullWithProps.Prop2 (type = customparamset)
#INFO : 	item #: PropModel.NullWithProps.Prop3 (type = customparamset)
#INFO : 	item #: PropModel.NullWithProps.MyProp (type = customparamset)
#INFO : 	item #: PropModel.NullWithProps.PROP4 (type = customparamset)
#INFO : -----
#INFO : TEST: Filter(,,"*Prop*")
#INFO :       [Properties under the Null with Prop somewhere in the FullName]
#INFO : Size of collection: 7
#INFO : 	item #: PropModel.NullWithProps.Prop1 (type = customparamset)
#INFO : 	item #: PropModel.NullWithProps.Prop2 (type = customparamset)
#INFO : 	item #: PropModel.NullWithProps.Prop3 (type = customparamset)
#INFO : 	item #: PropModel.NullWithProps.MyProp (type = customparamset)
#INFO : 	item #: PropModel.NullWithProps.Other (type = customparamset)
#INFO : 	item #: PropModel.NullWithProps.PROP4 (type = customparamset)
#INFO : 	item #: PropModel.NullWithProps.Scene_Material (type = material)

Related Examples

TrackCollection.Filter.2.pys

TrackCollection.Filter.3.js

TrackCollection.Filter.1.vbs

Keywords

TrackCollection Filter


Autodesk Softimage 2011