v11.0 (2013)
このコレクションのサブセットを、フィルタ基準に一致するオブジェクトの新しいコレクションとして戻します。項目が検出されなかった場合、このフィルタは"Nothing"を戻すので、エラーの捕捉に使用できます。
フィルタ条件は Type、Families、および Path パラメータを使用してセットアップできます。大別すると、Type はタイプ別に検索し(siType 定数を参照)、Families はファミリ別に検索し(siFamily 定数を参照)、Path はオブジェクトの名前で検索します(Path パラメータの構文については Object Name を参照)。
注:これらのパラメータを組み合わせることによって検索範囲を絞り込んだり広げたりすることができます。たとえば、Families パラメータに NURBS サーフェイスメッシュジオメトリ(siNurbsSurfaceMeshFamily)を指定するし、Path パラメータに'Cone*'を指定すると、元のコレクションに含まれていたすべての NURBS 三角錐を含むコレクションが戻されますが、ポリゴンメッシュ三角錐、NURBS カーブ、球などは戻されません。
CXSICollection XSICollection.Filter( String in_filter, Object in_famArray, String in_path ); |
oReturn = XSICollection.Filter( [Type], [Families], [Path] ); |
XSICollection (オリジナルのコレクションのサブセット)。
パラメータ | タイプ | 説明 |
---|---|---|
Type | String |
siType("Model"、"cube"、"torus"など)。タイプの引数を指定することは、各オブジェクトのタイプを ProjectItem.IsKindOf メソッドで調べることと同じです。
デフォルト値:空文字列 |
Families | siFamily または siFamily 値の Array |
オブジェクトが属しているファミリを指定します。フィルタに一致するには、オブジェクトは少なくとも指定されたファミリの 1 つに属している必要があります。
デフォルト値: 空の Variant |
Path | String |
Object Name。ワイルドカードを使用して、部分一致名を指定できます。たとえば、"a*" と指定すると、文字 "a" で始まるすべての一致オブジェクトが戻されます。
デフォルト値:空文字列 |
// Build a new scene with lots of objects to filter and return the scene root var child_coll = CreateCollection(); // 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 CreateCollection( ) { 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" ); var coll = new ActiveXObject( "XSI.Collection" ); var children = root.Children for (var i=0; i<children.count; i++) { coll.Add( children(i) ); } return coll; } /* -------------------------------------------------------------- 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) |