v1.0
Collection は複数のオブジェクトの"list"または"grouping"を格納するオブジェクトです。XSICollection は、通常、シーン内からのオブジェクトの一時リストを作成し、プロセスを処理するために使用されます。XSICollection の一般的な使用方法を、Shader オブジェクトに対する例の 1 つとして示します。
XSICollection のインスタンス化は継承されず、Group オブジェクトと違い、Scene の一部にはなりません。XSICollection の内容を保持する方法の 1 つが、CustomProperty 内の StringParameter 内部の XSICollection.GetAsText の戻り値を格納することです。
オブジェクトモデルには、その他多くのコレクションオブジェクト(PropertyCollection や ParameterCollection など)が含まれます。これらすべてのオブジェクトを列挙することは、Item と Count プロパティを使用することと同じです。ただし、その他のコレクションのみが 1 つのタイプのオブジェクトに含まれますが、スクリプトの記述者はこれらのコレクション内でオブジェクトを追加または削除できません。このため、XSICollection の使用は多くのスクリプトの中でも最も適しています。
また各スクリプト言語は、XSICollection オブジェクトに類似している独自の Array サポートを提供しています。この"ネイティブ"コレクションは、スクリプトの実装内では便利ですが、C++またはその他のスクリプト言語によって簡単に解釈することはできません。たとえば、カスタム Command は、JScript 配列を引数として受け取ることはできません。XSICollection がオブジェクトの表現文字列とオブジェクトモデルの表現間で変換する機能と同じような便利な機能は、これらのコレクションオブジェクトにはありません(XSICollection.SetAsText を参照)。
C++ API でこれに相当するオブジェクトは CRefArrayです。
| Add | AddItems | Expand | Filter |
| FindObjectsByMarkingAndCapabilities | GetAsText | Remove | RemoveAll |
| RemoveItems | SetAsText | ||
Dim oColl ' object pointer for collection
Dim oItem ' for enumerating the collection
Dim iCounter ' for looping through the collection
' Create the collection as an ActiveX object
Set oColl = CreateObject("XSI.Collection")
' Add some items to it
oColl.Add "Camera"
oColl.Add "Light"
' You can enumerate the collection...
For Each oItem In oColl
Application.LogMessage oItem
Next
' ... or loop through it...
For iCounter = 0 To oColl.Count - 1
Application.LogMessage oColl(iCounter)
Next
' ... or convert it to a string expression
Application.LogMessage oColl.GetAsText
' You can also find out if the collection is unique
Application.LogMessage "Is the collection unique? -- " & oColl.Unique
'--------------------------------------------------
' Output of above script:
'INFO : "Camera"
'INFO : "light"
'INFO : "Camera"
'INFO : "light"
'INFO : "Camera,light"
'INFO : "Is the collection unique? -- False" |
// Create the collection as an ActiveX object
var oColl = new ActiveXObject("XSI.Collection") ;
// Add the default camera by name
oColl.Add( "Camera" ) ;
// Add an item by its Object Model reference
var oNull = ActiveSceneRoot.AddNull() ;
oColl.Add( oNull ) ;
// You can enumerate the collection...
var eCollItems = new Enumerator( oColl );
eCollItems.moveFirst();
for (; !eCollItems.atEnd(); eCollItems.moveNext() )
{
var oItem = eCollItems.item();
Application.LogMessage( oItem ) ;
}
// ... or loop through it...
for (var iCounter = 0 ; iCounter < oColl.Count ; iCounter++ )
{
Application.LogMessage( oColl(iCounter) ) ;
}
// ... or convert it to a string expression
Application.LogMessage( oColl.GetAsText() ) ;
// By default collections are not set to Unique
Application.LogMessage( "Is the collection unique? -- " + oColl.Unique ) ;
//--------------------------------------------------
// Output of above script:
//INFO : Camera
//INFO : null
//INFO : Camera
//INFO : null
//INFO : Camera,null
//INFO : Is the collection unique? -- false |
'===========================================================
' This example demonstrates how to create an XSICollection,
' how to work with collection items, and how to set the
' get its family information
' Create the collection and the main object to go in it
Set oXSIColl = CreateObject( "XSI.Collection" )
Set oStuff = CreatePrim( "Torus", "MeshSurface" )
' Add the object to the new collection and print out
' the family info
getMembers oStuff
' Apply an operator to make the Families seach more
' interesting on the construction history
ApplyOp "Twist"
' Add each operator to the collection, etc.
Set oThingey = oStuff.ActivePrimitive.ConstructionHistory
For Each s in oThingey
getMembers s
Next
' Finally, what is in the XSICollection?
LogMessage "This collection contains these members:"
For Each c in oXSIColl
LogMessage vbTab & c & " (" & typename( c ) & ")"
Next
'========================================================
function getMembers( in_object )
' Make an empty collection item and assign an
' object to it.
Set oCache = CreateObject( "XSI.CollectionItem" )
oCache.Value = in_object
' Print out the family information on the new item
aMembership = oCache.Families
LogMessage in_object & " is a member of these families: "
LogMessage vbTab & aMembership & vbLf
' Assign the new collection item to the collection
oXSIColl.Add oCache
end function
'========================================================
'OUTPUT:
'INFO : "torus is a member of these families: "
'INFO : " 3D Objects
'"
'INFO : "torus.polymsh.twistop is a member of these families: "
'INFO : " Operators,DeformOperators
'"
'INFO : "torus.polymsh.geom is a member of these families: "
'INFO : " Operators,Converters
'"
'INFO : "This collection contains these members:"
'INFO : " torus (X3DObject)"
'INFO : " torus.polymsh.twistop (Operator)"
'INFO : " torus.polymsh.geom (Operator)" |