User Tools

Site Tools


Node Property Presentations

Summary

Below is an example demonstrating how you can use a property's presentation to provide a visual indication of information about the property.

API Areas of Interest

Example

Node_Property_Presentations.dsa
// Define an anonymous function;
// serves as our main loop,
// limits the scope of variables
(function( oNode ){
 
	/*********************************************************************/
	// Boolean : A function for testing whether or not a QObject instance
	// inherits one of a list of types
	function inheritsType( oObject, aTypeNames )
	{
		// If the object does not define the 'inherits' function
		if( !oObject || typeof( oObject.inherits ) != "function" ){
			// We are done... it is not a QObject
			return false;
		}
 
		// Iterate over the list of type names
		for( var i = 0, nTypes = aTypeNames.length; i < nTypes; i += 1 ){
			// If the object does not inherit the 'current' type
			if( !oObject.inherits( aTypeNames[i] ) ){
				// Next!!
				continue;
			}
 
			// Return the result
			return true;
		}
 
		// Return the result
		return false;
	};
 
	/*********************************************************************/
	// Array<DzProperty> : A function for getting a list of the properties in a group
	function getGroupProperties( oGroup, bTraverse, bRecurse )
	{
		// Declare an array to hold properties
		var aProperties = [];
 
		// If a group is not passed in
		if( !oGroup ){
			// We are done, return an empty array
			return aProperties;
		}
 
		// Get the number of proeprties in the group
		var nProperties = oGroup.getNumProperties();
		// Pre-size the properties array
		aProperties = new Array( nProperties );
		// Iterate over the properties, setting each element in the array
		for( var i = 0; i < nProperties; i += 1 ){
			// Assign the property to the position in the array
			aProperties[ i ] = oGroup.getProperty( i );
		}
 
		// If we are recursing
		if( bRecurse ){
			// Concatenate the properties array from child groups
			aProperties = aProperties.concat(
				getGroupProperties( oGroup.getFirstChild(), true, bRecurse ) );
		}
 
		// If we are traversing
		if( bTraverse ){
			// Concatenate the properties array from sibling groups
			aProperties = aProperties.concat(
				getGroupProperties( oGroup.getNextSibling(), bTraverse, bRecurse ) );
		}
 
		// Return the array of properties
		return aProperties;
	};
 
	/*********************************************************************/
	// Array<DzProperty> : A function for getting the list properties for an element
	function getElementProperties( oElement, bTraverse, bRecurse )
	{
		// Get the property group tree for the element
		var oPropertyGroupTree = oElement.getPropertyGroups();
 
		// If the application version is 4.9.4.101 or newer and we want all properties
		if( App.version64 >= 0x0004000900040065 && bTraverse && bRecurse ){
			// Return the properties for the element
			return oPropertyGroupTree.getAllProperties();
		}
 
		// Get the first group in the tree
		var oPropertyGroup = oPropertyGroupTree.getFirstChild();
		// Return the properties for the element
		return getGroupProperties( oPropertyGroup, bTraverse, bRecurse );
	};
 
	/*********************************************************************/
	// If nothing is selected
	if( !oNode ){
		// We are done..
		return;
	}
 
	// Get the properties available to the user by way of the selected node
	var aProperties = getElementProperties( oNode, true, true );
	// Declare variables we'll be using as we iterate
	var oProperty, oOwner, oPresentation;
	// Iterate over all properties
	for( var i = 0; i < aProperties.length; i += 1 ){
		// Get the 'current' property
		oProperty = aProperties[ i ];
		// Get the owner of the property
		oOwner = oProperty.getOwner();
 
		// Get the property's presentation
		oPresentation = oProperty.getPresentation();
		// If the property doesn't have a presentation
		if( !oPresentation ){
			// Next!!
			continue;
		}
 
		// If the property is on the node itself 
		if( inheritsType( oOwner, ["DzNode"] ) ){
			// Set the color
			oPresentation.colorA = new Color( 41, 41, 0 );
		// If the property is on a morph 
		} else if( inheritsType( oOwner, ["DzMorph"] ) ){
			// Set the color
			oPresentation.colorA = new Color( 0, 41, 0 );
		// If the property is on another element 
		} else {
			// Set the color
			oPresentation.colorA = new Color( 0, 41, 41 );
		}
 
		// If the name of the owner of the property begins with CTRL 
		if( oOwner.name.startsWith("CTRL") ){
			// Set the color
			oPresentation.colorB = new Color( 141, 141, 0 );
		// If the name of the owner of the property begins with FBM
		} else if( oOwner.name.startsWith("FBM") ){
			// Set the color
			oPresentation.colorB = new Color( 0, 141, 0 );
		// Everything else
		} else {
			// Set the color
			oPresentation.colorB = new Color( 0, 141, 141 );
		}
	}
 
// Finalize the function and invoke
})( Scene.getPrimarySelection() );