Search Tips

Search is based on keyword.

`Ex: "Procedures"`

Do not search with natural language

`Ex: "How do I write a new procedure?"`

Give Feedback Support Portal

# Q100277: Positioning nodes in the Katana Node Graph via Python

Warning: This article contains links to external websites

#### SUMMARY

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.

#### MORE INFORMATION

Creating nodes via Python

Nodes can be created in Katana using the following Python command:

    NodegraphAPI.CreateNode(nodeType, parent)

Where:

- 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:

    NodegraphAPI.SetNodePosition(node, (0,0))

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[0][0], pos[0][1]))

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 Q100064: How to raise a support ticket.