User Tools

Site Tools


Node Visibility Toggle

Summary

Below is an example demonstrating how to toggle a setting, in this case visibility, on the selected nodes in the scene, via script.

API Areas of Interest

Example

Node_Visibility_Toggle.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;
	};
 
	/*********************************************************************/
	// Declare working variable
	var oNode;
	// Get the selected nodes
	var aNodes = Scene.getSelectedNodeList();
	// Capture the number of selected nodes
	var nNodes = aNodes.length;
	// If we have no selected nodes
	if( nNodes < 1 ){
		// Inform the user
		MessageBox.warning(
			text( "You must select one or more nodes to perform this action." ),
			text( "Selection Error" ), text( "&OK" ), "" );
	// If we have selected nodes
	} else {
		// Start collecting changes
		beginUndo();
 
		// Iterate over the list of selected nodes
		for( var i = 0; i < nNodes; i += 1 ){
			// Get the 'current' node
			oNode = aNodes[i];
			// Toggle visibility of the node
			oNode.setVisible( !oNode.isVisible() );
		}
 
		// Finish collecting changes and add the undo to the stack
		acceptUndo( text( "Toggle Node Visibility" ) );
	}
 
// Finalize the function and invoke
})();