User Tools

Site Tools


Node FaceGroup Map

Summary

Below is an example demonstrating how to reveal the face group on a mesh that is associated with a given node, via script.

API Areas of Interest

Example

Node_FaceGroup_Map.dsa
// Define an anonymous function;
// serves as our main loop,
// limits the scope of variables
(function(){
 
	/*********************************************************************/
	// String : A function for retrieving a translation if one exists
	function text( sText )
	{
		// If the version of the application supports qsTr()
		if( typeof( qsTr ) != "undefined" ){
			// Return the translated (if any) text
			return qsTr( sText );
		}
 
		// Return the original text
		return sText;
	};
 
	/*********************************************************************/
	// Define common strings
	var sTitle = text( "Selection Error" );
	var sButton = text( "&OK" );
 
	// Get the selected node
	var oNode = Scene.getPrimarySelection();
	// If no node is selected
	if( !oNode ){
		// Inform the user
		MessageBox.critical( text( "No node selected." ), sTitle, sButton );
 
		// We are done...
		return;
	}
 
	// Declare a variable to capture the skeleton (if any)
	var oSkeleton = undefined;
	// If the primary selection is a bone
	if( oNode.inherits( "DzBone" ) ){
		// We need the skeleton
		oSkeleton = oNode.getSkeleton();
	// If the primary selection is a skeleton
	} else if( oNode.inherits( "DzSkeleton" ) ){
		// That is the node we need
		oSkeleton = oNode;
	}
 
	// Get the selection map
	var oSelectionMap = (oSkeleton ? oSkeleton.getSelectionMap() : oNode.getSelectionMap());
	// If we do not have a selection map
	if( !oSelectionMap ){
		// Inform the user
		MessageBox.critical( text( "No selection map." ), sTitle, sButton );
 
		// We are done...
		return;
	}
 
	// Declare working variable
	var sGroup;
 
	// Get the list of nodes that should be in the selection map
	var aNodes = (oSkeleton ? oSkeleton.getAllBones() : [ oNode ] );
	// Iterate over the nodes
	for( var i = 0, nNodes = aNodes.length; i < nNodes; i += 1 ){
		// Get the 'current' node
		oNode = aNodes[ i ];
		// Get the group for the node
		sGroup = oSelectionMap.findGroupForNode( oNode );
		// If the node is not in the map
		if( sGroup.isEmpty() ){
			// Report information
			print( "The", oNode.name, "node is not associated with a face group." );
 
			// Next!!
			continue;
		}
 
		// Report information
		print( "The", oNode.name, "node uses the", sGroup, "face group." );
	}
 
// Finalize the function and invoke
})();