Jump to content

python - node calls itself

Recommended Posts


Can I somehow call the the node itself? Example:

A node calls itself in the creation to rename itself from "my_node" to "more_owesome_node"

Edited by JJ FX

Share this post

Link to post
Share on other sites

Hi JJ, important is the variable on the left side, when creating:
node_mrg = hou.node(container).createNode('object_merge',name_mrg)

You can then refer to this node like this:


Here is whole example:


# define
offsetx = 3
offsety = 0
color = hou.Color(0.0, 0.0, 0.0)

node_src = hou.selectedNodes()[0]
name_src = node_src.name()

posx = node_src.position()[0] + offsetx
posy = node_src.position()[1] + offsety

#create, name, pos
container = node_src.parent().path()
name_mrg = "IN_" + name_src
node_mrg = hou.node(container).createNode('object_merge',name_mrg)
node_mrg.setPosition( [posx,posy] )

path_src = node_src.path()
parm = node_mrg.parm("objpath1")



  • Like 1

Share this post

Link to post
Share on other sites

In the Operator Type Properties → Scripts tab select "On Created" event handler, change "Edit as" to Python. Here is basic code:

node = kwargs['node']

For default operators you need to make a shelf tool and create node and change it's name manually in the tool script.


Custom assets also use tool script. In Operator Type Properties → Tools tab and the tool script looking like this:

import soptoolutils

soptoolutils.genericTool(kwargs, '$HDA_NAME')

The function call at the last line returns fully created node instance. After On Created event was executed. You can use it too:

import soptoolutils

node = soptoolutils.genericTool(kwargs, '$HDA_NAME')

It's more logical to use On Created, but sometimes it doesn't work. For example, if I remember correctly, you can't set node position in it, it will be overridden.

  • Like 1
  • Thanks 1

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now