David Tonkin
David Tonkin

Reputation: 85

Katana Nodes created with Python not updating properly

This Code in Katana/Python creates a Backdrop and resizes around any nodes that the user has selected:

nodeGraphTab = UI4.App.Tabs.FindTopTab('Node Graph')
nodeGraphTab._NodegraphPanel__fitBackdropNode()

If you were to manually create a node (or multiple), select the nodes then run that code, it will create something like this: enter image description here

BUT if I make a node programmatically and select it programmatically, my code only creates the Backdrop, but fails to resize and move it. It's almost as if the creation of the node needs to be "baked" in somehow before its recognised.

My code:

import NodegraphAPI

# Get the root node
rootNode = NodegraphAPI.GetRootNode()

#Create a Node
node = NodegraphAPI.CreateNode("Alembic_In", rootNode)

#Select the node in the viewport
NodegraphAPI.SetNodeSelected(node, True)

nodeGraphTab = UI4.App.Tabs.FindTopTab('Node Graph')
nodeGraphTab._NodegraphPanel__fitBackdropNode()

The above code produces this incorrect result:

enter image description here

Could try this code in Katana and let me know what Im doing wrong?
I'm using Katana 5.0v1

Upvotes: 0

Views: 569

Answers (1)

David Tonkin
David Tonkin

Reputation: 85

I got the answer from Christian over that the Foundry forum:

When a node is created, it remains shapeless until it has to be drawn for the first time, which only occurs in the next iteration of the event loop. The NodegraphWidget.fitBackdropNode() method relies on node shapes to calculate the extent of the Backdrop node. If the node shapes are not available yet, a minuscule Backdrop node is created, as your snippet demonstrates.

In order to ensure that node shapes are created in time, event processing can be requested with Utils.EventModule.ProcessEvents(). Blockquote

> import NodegraphAPI
> 
> #Get the root node rootNode = NodegraphAPI.GetRootNode()
> 
> #Create a Node node = NodegraphAPI.CreateNode("Alembic_In", rootNode)
> 
> #Select the node in the viewport NodegraphAPI.SetNodeSelected(node, True)
> 
> Utils.EventModule.ProcessEvents()  # Process events (node_create
> events in particular) to ensure that the node's shape is created
> 
> nodeGraphTab = UI4.App.Tabs.FindTopTab('Node Graph')
> nodeGraphTab.getNodeGraphWidget().fitBackdropNode()

Also, note that, instead of _NodegraphPanel__fitBackdropNode() (a pseudo-private method), NodegraphWidget.fitBackdropNode() can be used instead.

Upvotes: 0

Related Questions