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(){
 
	/*********************************************************************/
	// 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 isn't passed in
		if( !oGroup ){
			// We're 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();
		// Get the first group in the tree
		var oPropertyGroup = oPropertyGroupTree.getFirstChild();
		// Return the properties for the element
		return getGroupProperties( oPropertyGroup, bTraverse, bRecurse );
	};
 
	/*********************************************************************/
	// Get the primary selection
	var oNode = Scene.getPrimarySelection();
	// If nothing is selected
	if( !oNode ){
		// We're 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( oOwner.inherits( "DzNode" ) ){
			// Set the color
			oPresentation.colorA = new Color( 41, 41, 0 );
		// If the property is on a morph 
		} else if( oOwner.inherits( "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
})();