Get the actual node position in OnCreated Python event

   329   2   1
User Avatar
Member
25 posts
Joined: 8月 2017
Offline
When we create a node and print its .position()in its OnCreatedscript, it's going to return the origin of the network editor (0, 0), even if we placed the node elsewhere.

How can we get the actual position in the OnCreatedevent?

I need it to add another node right before it. I was suggested to use .moveToGoodPosition()and it partially solves the problem when we connect to an existing node, I assume because this function grabs the inputs position (which already exists and has a proper .position()), but when we don't connect to anything, this function no longer works in OnCreated, and afterwards when repeated manually in the Python Shell, the exact same command works.
User Avatar
Member
218 posts
Joined: 5月 2017
Offline
Hi,

at the time on create is fired the position is not defined, you can use the following to set a post event.

OnCreate:
node = kwargs['node']

def callback(event_type, **kwargs):
    print(node.position())
    node.removeEventCallback((hou.nodeEventType.PositionChanged, ), callback)

node.addEventCallback((hou.nodeEventType.PositionChanged, ), callback)
User Avatar
Member
25 posts
Joined: 8月 2017
Offline
Very clever, I think this solves everything. Thanks a lot!
  • Quick Links