Finding User Data in a Scene

 
 
 

You may need to find out whether a scene contains any user data. You may also need to return or assign the stored values on a user data map or blob. To do so, you need to find the object or cluster to which the user data is associated.

Tip

You should choose a unique name for each user data map and blob you create so that multiple user data stored on a particular element do not create conflicts.

The following examples are provided:

VBScript Example: Finding a user data map

  1. Start from a scene that contains one or more user data maps.

  2. Get a list of geometry objects and their clusters.

  3. Get the properties of each cluster and weed out everything but the user data maps.

  4. Get the individual items on each user data map.

    Tip

    Since user data maps are applied to a cluster of items, each item can be set individually. To access the individual data on each cluster member, you need to use the UserDataMap.Item property to get the UserDataItem object where the values are stored.

' 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)."

JScript Example: Finding a user data blob

	/* 
		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"

Creative Commons License Except where otherwise noted, this work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License