User Tools

Site Tools


Node Properties

Summary

Below is an example demonstrating how you can collect all of the properties associated with a given node (presented in the context of the node within the interface), using the Property Group Tree instead of having to traverse all of the individual components that are actually involved.

API Areas of Interest

Example

Node_Properties.dsa
// DAZ Studio version 4.1.0.71
// 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 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 );
	};
 
	/*********************************************************************/
	// DzProperty : A function for finding a property associated with an element
	function findElementProperty( oElement, sProperty, bUseLabel )
	{
		// Whether or not to use optimizations; 4.7.1.44 or newer
		var bUseOptimization = (App.version64 >= 0x000400070001002c);
 
		// Declare a working variable
		var oProperty;
 
		// If the application version is 4.7.1.44 or newer and we are not using
		// the label to find, or the application version is 4.11.0.166 or newer
		if( (bUseOptimization && !bUseLabel) ||
			App.version64 >= 0x0004000b000000a6 ){
			// Get the property group tree for the element
			var oPropertyGroupTree = oElement.getPropertyGroups();
 
			// If we are using the label
			if( bUseLabel ){
				// Attempt to find the property
				oProperty = oPropertyGroupTree.findPropertyByLabel( sProperty );
			// If we are not using the label
			} else {
				// Attempt to find the property
				oProperty = oPropertyGroupTree.findProperty( sProperty );
			}
 
			// If we found a property
			if( oProperty ){
				// We are done, return it
				return oProperty;
			}
		// Otherwise
		} else {
			// Get the properties of the element
			var aProperties = getElementProperties( oElement, true, true );
			// Iterate over the properties
			for( var i = 0; i < aProperties.length; i += 1 ){
				// Get the 'current' property
				oProperty = aProperties[i];
 
				// If we are using the label
				if( bUseLabel ){
					// If the label of the property is the one we are looking for
					if( oProperty.getLabel() == sProperty ){
						// We are done, return it
						return oProperty;
					}
				// If we are not using the label
				} else {
					// If the name of the property is the one we are looking for
					if( oProperty.name == sProperty ){
						// We are done, return it
						return oProperty;
					}				
				}
			}
		}
 
		return null;
	};
 
	/*********************************************************************/
	// Array<DzProperty> : A function for getting the list properties for an element
	function getElementPropertiesInPath( oElement, sPath, bRecurse )
	{
		// If the path is empty
		if( !sPath ){
			// Return the properties for the element
			return getElementProperties( oElement, true, bRecurse );
		}
 
		// Initialize
		var oGroup = oElement.getPropertyGroups();
		var sName = "";
		var nIdx = -1;
		var sSubPath = sPath;
 
		// While the remaining path is not empty
		while( oGroup && !sSubPath.isEmpty() ){
			// Get the index of the first slash
			nIdx = sSubPath.indexOf( "/" );
			// If a slash was not found
			if( nIdx < 0 ){
				// The group name is the path
				sName = sSubPath;
				// Break the loop on the next evaluation
				sSubPath = "";
			// If a slash was found
			} else {
				// The group name is before the slash
				sName = sSubPath.left( nIdx );
				// Get the remaining path
				sSubPath = sSubPath.right( sSubPath.length - nIdx - 1 );
			}
 
			// Get the sub group
			oGroup = oGroup ? oGroup.findChild( sName ) : null;
		}
 
		// Return the properties for the element
		return getGroupProperties( oGroup, false, bRecurse );
	};
 
	/*********************************************************************/
	// void : A function for reporting information about a property
	function printPropertyInfo( oProperty )
	{
		// Get the owner of the property
		var oOwner = oProperty.getOwner();
 
		// Provide feedback
		print( String( "- %1 \"%2\" :: %3 (%4/%5) \"%6\"" )
			.arg( oOwner.className() )
			.arg( oOwner.name )
			.arg( oProperty.className() )
			.arg( oProperty.getPath() )
			.arg( oProperty.name )
			.arg( oProperty.getLabel() )
		);
	};
 
	/*********************************************************************/
	// Get the primary selection
	var oNode = Scene.getPrimarySelection();
	// If nothing is selected
	if( !oNode ){
		// We are done...
		return;
	}
 
 
	// Define what we are looking for
	var sPropertyName = "SubDAlgorithmControl";
	var sPropertyPath = "General/Mesh Resolution";
 
	// Initialize a list of properties
	var aProperties = [];
 
	// Declare working variable
	var oProperty;
	// If a property name is defined
	if( !sPropertyName.isEmpty() ){
		// Find the property by name on the node
		oProperty = findElementProperty( oNode, sPropertyName, false );
		// If the property is found
		if( oProperty ){
			// Collect the property
			aProperties.push( oProperty );
		}
	// If a property path is defined
	} else if( !sPropertyPath.isEmpty() ){
		// Collect the properties at the specified path on the node
		aProperties = aProperties.concat( getElementPropertiesInPath( oNode, sPropertyPath, true ) );
	// If neither a property name nor a property path is defined
	} else {
		// Collect the properties on the node
		aProperties = aProperties.concat( getElementProperties( oNode, true, true ) );
	}
 
	// Iterate over the collected properties
	for( var i = 0; i < aProperties.length; i += 1 ){
		// Get the 'current' property
		oProperty = aProperties[ i ];
 
		// Print information about the property
		printPropertyInfo( oProperty );
	}
 
// Finalize the function and invoke
})();