User Tools

Site Tools


Getting the properties associated with a node.

Author: Rob Whisenant, © 2008


I have seen several cases where someone was expecting DzElement::getPropertyList()… (as shown below)

const oNODE = Scene.getPrimarySelection(); 
if( oNODE ){
	const aPROPERTIES = oNODE.getPropertyList();
	var oProperty, oOwner;
	for( var i = 0; i < aPROPERTIES.length; i++ ){
		oProperty = aPROPERTIES[ i ];
		oOwner = oProperty.getOwner();
		print( String( '%1 : %2 : %3' ).arg( oOwner.className() ).arg( oProperty.name ).arg( oProperty.getLabel() ) );
	}
}

…to return an array of all the properties associated with a node, not realizing/understanding that all DzElement derived objects own their own properties.

Having seen this more than a few times, I thought I'd take the oppertunity to show a way to use the node's Property Group Tree (through inheritence of DzElement) to do what I suspect the intent was. Below you will find a sample script that will print [to the output console of the DAZ Script IDE as well as the DAZ Studio log file] information pertaining to all properties that are displayed, at the node level, in the Parameters tab [when Show Hidden Properties is active] for a given node.

/*********************************************************************/
// Array<DzProperty> :
function getGroupProperties( oGROUP, bTRAVERSE, bRECURSE ){
	var aProperties = new Array();
	if( !oGROUP ){ return aProperties; }
	else{
		const nPROPERTIES = oGROUP.getNumProperties();
		for( var i = 0; i < nPROPERTIES; i++ ){
			aProperties.push( oGROUP.getProperty( i ) );
		}
 
		if( bRECURSE ){ aProperties = aProperties.concat( getGroupProperties( oGROUP.getFirstChild(), bTRAVERSE, bRECURSE ) ); }
		if( bTRAVERSE ){ aProperties = aProperties.concat( getGroupProperties( oGROUP.getNextSibling(), bTRAVERSE, bRECURSE ) ); }
	}
 
	return aProperties;
}
 
/*********************************************************************/
// Array<DzProperty> :
function getNodeProperties( oNODE, bTRAVERSE, bRECURSE ){
	const oPROPERTY_GROUP_TREE = oNODE.getPropertyGroups();
	const oPROPERTY_GROUP = oPROPERTY_GROUP_TREE.getFirstChild();
 
	return getGroupProperties( oPROPERTY_GROUP, bTRAVERSE, bRECURSE );
}
 
/*********************************************************************/
const oNODE = Scene.getPrimarySelection();
if( oNODE ){
	const aPROPERTIES = getNodeProperties( oNODE, true, true );
	var oProperty, oOwner;
 
	for( var i = 0; i < aPROPERTIES.length; i++ ){
		oProperty = aPROPERTIES[ i ];
		oOwner = oProperty.getOwner();
		if( oOwner.inherits( 'DzNode' ) ){
			print( String( '%1 : %2 : %3' ).arg( oOwner.className() ).arg( oProperty.name ).arg( oProperty.getLabel() ) );
		}
		else{
			print( String( '%1 : %2 : %3' ).arg( oOwner.className() ).arg( oOwner.name ).arg( oProperty.getLabel() ) );
		}
	}
}

Notice the difference in what the first and second scripts produce. The first script only provides the properties owned explicitly by the node, while the second script provides all properties displayed in the Parameters tab, at the node level.