Jump to content

python - node calls itself


JJ FX

Recommended Posts

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:
node_mrg.setName("newname")

 

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] )

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

#setcol
node_src.setColor(color)
node_mrg.setColor(color)

 

  • Like 1
Link to comment
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']
node.setName('some_special_name')

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')
node.setName('some_special_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
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...