This article explains how to position newly created nodes in the Node Graph, via Python commands.
For more information on scripting in Katana and how to work with nodes, please see the Working with Nodes section of the Katana Developer Guide.
Creating nodes via Python
Nodes can be created in Katana using the following Python command:
- The nodeType is the node name as it appears in the list of available nodes. You can access this list by hovering the mouse over the Node Graph tab and pressing the Tab button .
- The parent can either be the root node or a Group node within the node graph. Without a parent, the node you are trying to create will not appear in the UI.
For example, to add a CameraCreate node in the node graph, use the following command:
node = NodegraphAPI.CreateNode("CameraCreate", NodegraphAPI.GetRootNode())
Default node position
When creating new nodes via Python, they will always be placed at the centre of the Node Graph, with the node position being (0,0). This is not always at the centre of the part of the Node Graph that is currently visible in the Node Graph tab, and you may have to pan the viewport to find the new node.
This default behaviour corresponds to the following Python command:
Positioning nodes in the Node Graph via Python
To place the new node in the centre of the current Node Graph viewport you can query the visible portion of the Node Graph and position the node by using the following Python commands:
root = NodegraphAPI.GetRootNode()
pos = NodegraphAPI.GetViewPortPosition(root)
# this returns a tuple containing the position and scale of the view information of a group network. This works because the Root node is also a Group node
node = NodegraphAPI.CreateNode("CameraCreate", root)
NodegraphAPI.SetNodePosition(node, (pos, pos))
If you are encountering any issues with this, then please open a Support ticket and let us know about the problem and which troubleshooting steps you have taken so far.
For more information on how to open a Support ticket, please refer to the 'Using the Support Portal' article.