# Scripting Nodes¶

## Prerequisites¶

• The following methods are exposed by the NodeCreation, NodeControl and NodeSelection objects implemented by the module Thinkbox.Sequoia.Nodes
• Before calling these methods, you must ensure the module is imported.
import Thinkbox.Sequoia.Nodes 1.0


## Creating Nodes¶

<String> NodeCreation.createPointLoader ( <QUrl>defaultFile, <Bool>promptFile )

• Creates a new Point Loader.
• The first argument defines the file name to use as the point data source. It can be an empty string.
• The second argumemt controls whether to prompt the user to pick a source file manually (true), or not (false).

<String> NodeCreation.createPointROI ( <String>nodeId )

• Creates a new Point Region Of Interest object.
• The first and only argument defines the node handle of a source object - either a Point Loader, or another Point Region Of Interest.
• The argument can be passed as undefined to create an object without a connection.
• To connect multiple input sources, you must set the sources input property after the object is created.

<String> NodeCreation.createMesher ( <String>nodeId, [ <Bool>useSuggestedRadius ] )

• Creates a new Mesher object.
• The first argument defines the node handle of a source object - either a Point Loader, or a Point Region Of Interest.
• The argument can be passed as undefined to create an object without a connection.
• To connect multiple input sources, you must set the sources input property after the object is created.
• The second (optional) argument is a boolean value.
• If supplied as true, or not specified, the suggested radius calculated by the Mesher will be used.
• If supplied as false, the radius will not be set and has to be set by the script by modifying the inRadius property, or by the user via the UI.

<String> NodeCreation.createMeshLoader ( <String>defaultFile, <Bool>promptFile, <Bool>autobuild )

• Creates a new Mesh Loader object.
• The first argument is the file name to load - if can be passed as empty string if no file should be loaded by the script.
• The second argument is a boolean flag controlling whether to prompt the user to pick a file manually.
• When passing an empty string as the file name, you might want to set the second argument to true.
• When passing a valid file name as the first argument, the second argument should be set to false.
• The third argument is a boolean flag that controlling whether to auto-update the object after creation.

<String> NodeCreation.createImageProjection ( <String>defaultFile, <Bool>promptFile )

• Creates a new Image Projection object
• The first argument defines the file name to use as the image source. It can be an empty string.
• The second argumemt controls whether to prompt the user to pick an image file manually (true), or not (false).

<String> NodeCreation.createSurfacePoints ( <String>nodeId )

• Creates a new Surface Points object.
• The first and only argument defines the node handle of a source object - either a Mesher, or a Mesh Loader.
• The argument can be passed as undefined to create an object without a connection.
• To connect multiple input sources, you must set the sources input property after the object is created.

<String> NodeCreation.createMarker ( [ <Vector3D>position ] )

• Creates a new Marker object.
• The first and only optional argument defines the node’s position.
• If not specified, the Marker will be created at the World Origin.

<String> NodeCreation.createCamera ()

• Creates a new Camera in the Active Document and in the Active Viewport.

## Collecting Nodes¶

<StringList> NodeControl.getAllNodes ( [ <String>documentId ] );

• Returms a list of all node IDs in the Document.
• The first, optional argument is the ID of the Document - if not specified, the Active Document will be used.

<StringList> NodeControl.getAllNodesOfType ( <String>type, [ <String>documentId ] );

• Returns a list of all node IDs in the Document that match the specified type.
• The first argument is the Type String, e.g. “PointLoader”, “Mesher” etc.
• The second, optional argument defines the Document ID. If not specified, the Active Document will be used.
• See also NodeControl.getNodeType() for the related method returning the Type String of a node.

## Node Selection¶

<void> NodeSelection.setSelectedNode ( <String>nodeId )

• Sets the selection to the specified node.
• Any other selected nodes will be deselected automatically.
• The first and only argument is the ID of the node to select.

Example:

var a1 = NodeCreation.createPointLoader('', true); //create a Point Loader
var a2 = NodeCreation.createMesher(a1); // create a Mesher connected to it
//At this point, the Mesher would be selected


• Selects the specified node, while retaining the existing selection.
• The first and only argument is the ID of the node to add to the selection.

Example:

var a1 = NodeCreation.createPointLoader('', true); //create a Point Loader
var a2 = NodeCreation.createMesher(a1); // create a Mesher connected to it
//At this point, the Mesher would be selected
//At this point, both objects are selected


<void> NodeSelection.removeSelectedNode ( <String>nodeId )

• Deselects the specified node, while keeping the rest of the selected node in the selection set.
• The first and only argument is the ID of the node to remove from the selection.

<void> NodeSelection.clearSelectedNodes ( <String>documentId )

• Deselects all nodes in the specified Document.
• The first and only argument is the Document ID.

<stringList> NodeSelection.getSelectedSequoiaNodes ()

• Returns the selected nodes as a list of Node IDs.

Example:

//Manually select several objects in the Document... then evaluate:
var s1 = NodeSelection.getSelectedSequoiaNodes(); //get the selected object
console.log( s1 );  //output the selected node IDs


## Accessing Node Properties¶

<variant> NodeControl.getNodeProperty ( <String>nodeId, <String>propertyName, [ <String>documentId ] )

• Returns the value of the specified property in the given node and document.
• The type of the return value will depend on the property’s value type.
• Note that JavaScript variables are type-free, so any value would be accepted if assigned to a variable.
• The first argument specifies the Node ID.
• The second argument provides the string with the name of the property to query.
• The third, optional argument specifies the Document ID.

Example:

var n0 = NodeCreation.createPointLoader('',true); //create a Point Loader, let the user pick the file name
var response = NodeControl.getNodeProperty( n0, "inFilename" ); //get the filename property of the first selected object
console.log( response ); //and output to the Log to see what the user picked...


<void> NodeControl.setNodeProperty ( <String>nodeId, <String>propertyName, <Variable>value, [ <String>documentId ] )

• Sets the value of the property in the given node and document to the provided value.
• The first argument specifies the Node ID.
• The second argument provides the string with the name of the property to query.
• The third, optional argument specifies the Document ID.

<StringList> NodeControl.getAllNodePropertyNames ( <String>nodeId, [ <String>documentId ] )

• Returns all property names available in the specified node as a list of strings.
• The first argument specifies the Document ID.
• The second argument specifies the Node ID.

<Vector3D> NodeControl.getNodePosition ( <String>nodeId, [ <String>documentId ] )

• Returns the scene object’s world space Position.
• The first argument specifies the Node ID.
• The second, optional argument specifies the Document ID.
• If not specified, or if supplied as empty string, the current Document will be used implicitly.

<Quaternion> NodeControl.getNodeOrientation ( <String>nodeId, [ <String>documentId ] );

• Returns the scene object’s world space Orientation.
• The first argument specifies the Node ID.
• The second, optional argument specifies the Document ID.
• If not specified, or if supplied as empty string, the current Document will be used implicitly.

<Vector3D> NodeControl.getNodeScale ( <String>nodeId, [ <String>documentId ] );

• Returns the scene object’s world space Scale.
• The first argument specifies the Node ID.
• The second, optional argument specifies the Document ID.
• If not specified, or if supplied as empty string, the current Document will be used implicitly.

<void> NodeControl.setNodePosition ( <Vector3D>position, <String>nodeId, [ <String>documentId ] );

• Sets the scene object’s world space Position to the first argument.
• The second argument specifies the Node ID.
• The third, optional argument specifies the Document ID.
• If not specified, or if supplied as empty string, the current Document will be used implicitly.

<void> NodeControl.setNodeOrientation ( <Quaternion>orientation, <String>nodeId, [ <String>documentId ] );

• Sets the scene object’s world space Orientation to the first argument.
• The second argument specifies the Node ID.
• The third, optional argument specifies the Document ID.
• If not specified, or if supplied as empty string, the current Document will be used implicitly.

<void> NodeControl.setNodeScale ( <Vector3D>scale, <String>nodeId, [ <String>documentId ] );

• Sets the scene object’s world space Scale to the first argument.
• The second argument specifies the Node ID.
• The third, optional argument specifies the Document ID.
• If not specified, or if supplied as empty string, the current Document will be used implicitly.

Example:

var sel = NodeSelection.getSelectedSequoiaNodes(); //get the selected objects
var i = 0;
for (i = 0; i < sel.length; i++) {
var pos = NodeControl.getNodePosition ( sel[i] ); //get the i-th node's position
pos.x += 1.0; //move the object 1 meter along X
NodeControl.setNodePosition ( pos, sel[i] ); // set the position of the node
}


<String> NodeControl.getNodeName ( <String> nodeId, [ <String> documentId ] );

• Returns the name of the node as a string value.
• The first argument is the ID of the node.
• The second, optional argument is the ID of the Document - if not specified, the Active Document will be used.

<String> NodeControl.getNodeType ( <String> nodeId, [ <String> documentId ] );

• Returns the type of the node.
• The first argument is the ID of the node.
• The second, optional argument is the ID of the Document - if not specified, the Active Document will be used.

Example:

var sel = NodeControl.getAllNodes(); //get all nodes in the Active Document
var i = 0;
for (i = 0; i < sel.length; i++) {
var name = NodeControl.getNodeName ( sel[i] ); //get the i-th node's name
var type = NodeControl.getNodeType ( sel[i] ); //get the i-th node's type
console.log ( "Node ID:" + sel[i] + " Name:"+ name + " Type:" +  type );
}


<VariantList> NodeControl.getNodeBoundingBox ( <Bool>worldspace, <String>nodeId, [<String> documentId ] );

• Returns an array of Position vectors representing each of the 8 corners of the node’s bounding box.
• Note that the values will be stored as 32 bit Singles.
• See below for methods that return 64 bit Doubles.
• The first argument controls whether the world-aligned bounding box (True) or the object-aligned bounding box (when False) will be returned.
• The second argument supplies the node to query.
• The third optional argument provides the Document ID. When not supplied, the Active Document will be used.

<List of doubles> NodeControl.getMinBoundingBox ( <String> nodeId, [ <String> documentId ] );

<List of doubles> NodeControl.getMaxBoundingBox ( <String> nodeId, [ <String> documentId ] );

• Return the Minimum and Maximum of the specified node’s bounding box as lists of Doubles.

<void> NodeControl.setMesherUCSSource ( <String> mesherId, <String>UcsId, [ <String> documentId ] );

• Sets the UCS node of a Mesher.
• The first argument defines the Node ID of the Mesher node.
• The second argument defines the Node ID of the UserCoordinateSystem node.
• The third, optional argument defines the Document ID. If not specified, the Active Document will be used.

<void> NodeControl.removeMesherUCS ( <String> mesherID, [ <String> documentId ] );

• Removes the UCS node of a Mesher.
• The first argument defines the Node ID of the Mesher node.
• The second, optional argument defines the Document ID. If not specified, the Active Document will be used.