シーンにユーザ データが含まれているかどうかを確認しなければならない場合があります。 また、ユーザ データ マップやブロブに保存された値を戻したり割り当てる必要もあります。 そのためには、ユーザ データが関連付けられたクラスタまたはオブジェクトを検索する必要があります。
ユーザ データ マップは項目のクラスタに適用されるため、各項目は個別に設定することができます。 各クラスタ メンバの個別のデータにアクセスするには、UserDataMap.Item プロパティを使用して、値が格納されている UserDataItem オブジェクトを取得する必要があります。
' Get a list of geometry objects Set oFoundThings = ActiveSceneRoot.FindChildren(,,siGeometryFamily) ' Set the counter to measure the number of user data maps iCount = 0 For Each t in oFoundThings ' Print the geometry information LogMessage "=======================================================" LogMessage "Found a " & TypeName(t) & " called " & t.Name ' Get the clusters on the current geometry Set oClusters = t.ActivePrimitive.Geometry.Clusters ' Enumerate each cluster for its properties For Each c in oClusters Set oProps = c.Properties ' Check each property to see if it's a user data map For Each p in oProps If TypeName(p) = "UserDataMap" Then ' Increment the counter iCount = iCount + 1 End If Next Next Next LogMessage "=======================================================" LogMessage "Found " & iCount & " user data map(s)." ' OUTPUT OF SCRIPT (assuming an object called "grid" with a user data map on it) 'INFO : "=======================================================" 'INFO : "Found a X3DObject called grid" 'INFO : "=======================================================" 'INFO : "Found 1 user data map(s)."
/*
This example demonstrates how to find UserDataBlobs in a scene
*/
NewScene( null, false);
// --------------------------------------------------------------------
// SETUP
//
// Set up the scene by creating a null to hold the blobs and then
// adding two blobs (one empty and one populated)
var oNull = ActiveSceneRoot.AddNull();
var oBlob1 = oNull.AddProperty( "UserDataBlob", false, "nulldata" );
oBlob1.Value = "xyz123";
oNull.AddProperty( "UserDataBlob", false, "emptynulldata" );
// --------------------------------------------------------------------
// SEARCH
//
// Find all UserDataBlobs on the object and print out their values
var e = new Enumerator( oNull.Properties );
var item ;
for ( ;!e.atEnd();e.moveNext() )
{
item = e.item();
if ( item.Type == "UserDataBlob" )
{
if ( item.IsEmpty )
{
LogMessage( "Found empty UserDataBlob called " + item.Name );
}
else
{
LogMessage( "Found user data blob called " + item.Name +
" with value " + item.Value );
}
}
}
// --------------------------------------------------------------------
// RESULT
//
// The following output is logged to the Script Editor:
//INFO : "Found user data blob called nulldata with value xyz123"
//INFO : "Found empty UserDataBlob called emptynulldata"