Creating node using Python and shortcuts for newbies

   1865   2   0
User Avatar
Member
36 posts
Joined: 1月 2014
Offline
Hi,

I'm relatively new to the world of Python and would obviously like to start implementing slowly in my practice. I've created a small script that allows me to create an object_merge node from the selected node in my network.

Please feel free to correct my coding or suggest easier way of doing thigs. Very new at this whole Python thing

Here's my code :

#selectedNodes creates an array/list of the nodes that were selected.
nodes = hou.selectedNodes()

#Me node of interest is the first one in this case, hence nodes
#print nodes
name = nodes.name()


#We need to get the full path of where to create the new nodes
parent = nodes.parent()
path = parent.path()

#print parent
#print path

#We need to create the object merge node
objectMerge = parent.createNode(“object_merge”)
parm = objectMerge.parm(“objpath1”)
parm.set(nodes.path())
objectMerge.setName(“merge_in_” + name)


#Get mouse position and print
net_editor = hou.ui.paneTabOfType(hou.paneTabType.NetworkEditor)
#print net_editor.cursorPosition()
#print net_editor

objectMerge.setPosition(net_editor.cursorPosition())



I'm running into an issue where I can't use this more than once in my network since two nodes can't have the same name. So how do we solve this?

Thanks!
User Avatar
Member
900 posts
Joined: 2月 2016
Offline
Hi,
from the documentation of the setName function
If the unique_name parameter is set to True, the supplied name may be changed to ensure that it doesn’t match the name of any existing node.

might it be of help?
User Avatar
Member
36 posts
Joined: 1月 2014
Offline
Thanks Andr, that works fine
  • Quick Links