User Tools

Site Tools


Node Align

Summary

Below is an example demonstrating how to adjust the positions of nodes in the scene in order to align them according to settings that correspond to those found on the Align (WIP) pane, via script.

API Areas of Interest

Example

Node_Align.dsa
// DAZ Studio version 4.10.0.122 filetype DAZ Script
 
// 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 message variables
	var sTitle = text( "Selection Error" );
	var sMessage = text( "You must select one or more nodes to perform this action." );
	var sButton = text( "&OK" );
 
	// Get the selected nodes
	var aNodes = Scene.getSelectedNodeList();
	// Get the number of nodes
	var nNodes = aNodes.length;
	// If we do not have nodes
	if( nNodes < 1 ){		
		// Alert the user
		MessageBox.warning( sMessage, sTitle, sButton, "" );
 
		// We are done...
		return;
	}
 
	// Create a node aligner
	var oAligner = new DzNodeAligner();
 
	// Declare working variables
	var nCode;
	var oNode;
 
	// Iterate over the nodes
	for( var i = 0; i < nNodes; i += 1 ){
		// Get the 'current' node
		oNode = aNodes[ i ];
		// Add the node to the aligner; capture errors
		nCode = oAligner.addNode( oNode );
		// If there was an error
		if( nCode != 0x00000000 ){
			// Provide feedback
			print( getErrorMessage( nCode ) );
		}
	}
 
	// Set the X axis options
	oAligner.setXAlign( DzNodeAligner.StackXLefts );
	oAligner.setXUnits( 1, DzNodeAligner.UnitsFT );
	oAligner.setXUseInterval( true );
 
	// Set the Y axis options
	oAligner.setYAlign( DzNodeAligner.StackYTops );
	oAligner.setYUnits( 1, DzNodeAligner.UnitsFT );
	oAligner.setYUseInterval( true );
 
	// Set the Z axis options
	oAligner.setZAlign( DzNodeAligner.StackZBacks );
	oAligner.setZUnits( 1, DzNodeAligner.UnitsFT );
	oAligner.setZUseInterval( true );
 
	// If alignment is possible
	if( oAligner.canAlign() ){
		// Start capturing changes
		beginUndo();
		// Perorm the alignment; if it is not successful
		if( !oAligner.doAlign() ){
			// Cancel/Purge the collection of changes
			cancelUndo();
		// If alignment is successful
		} else {
			// Add the undo to the stack
			acceptUndo( "Align Nodes" );
		}
	// If alignment is not possible
	} else {
		//
		sMessage = text( "The current selection, with the current options, cannot be aligned." );
		// Alert the user
		MessageBox.warning( sMessage, sTitle, sButton, "" );
	}
 
// Finalize the function and invoke
})();