Houdini Python practice. It sounds like a redevelopment of the wheel, but the content is "connect the selected SOP node to Merge".
selNodes = hou.selectedNodes()
mrgNode = selNodes[0].parent().createNode('merge')
mrgNode.moveToGoodPosition()
mrgNode.setDisplayFlag(True)
mrgNode.setRenderFlag(True)
for i,node in enumerate(selNodes):
mrgNode.setInput(i,node)
#node.moveToGoodPosition()
mrgNode.setSelected(True, clear_all_selected=True)
If you add this to the shelf, select multiple nodes and then run Like this. A Merge node is created, and the selected nodes are connected to it in a batch.
hou.selectedNodes()
Is the super classic "Get selected now". It will be returned in the list.
selNodes[0].parent()
Get the hierarchy where the node you are currently selecting is located. So use the createNode
method to create a node. A Merge SOP is created with createNode ('merge')
.
moveToGoodPosition()
It will move the node "in a good position" on the network editor. I used it in the for loop in the latter half, but I commented it out because it wasn't arranged very well. (Uncomment and compare the behavior.)
mrgNode.setDisplayFlag(True)
mrgNode.setRenderFlag(True)
The display flag and render flag of the node are turned on.
for i,node in enumerate(selNodes):
mrgNode.setInput(i,node)
The selected node is turned in a for loop.
By passing the node to the setInput
method of the Merge node you created earlier, that node will be connected to the Merge input. It's like connectAttr
in Maya.
The first argument of setInput
allows you to specify the number to connect the node to. I'm using ʻenumerate to get the loop order ʻi
, so I'm passing it.
mrgNode.setSelected(True, clear_all_selected=True)
Finally, put the Merge node you just created into the ** selected state **. You can put it in the place where you turn on the flag. It's not a "select" command, but a "select" command.
selectedNodes http://www.sidefx.com/docs/houdini15.0/hom/hou/selectedNodes
Click here for parent (), moveToGoodPosition (), setInput (), setSelected () http://www.sidefx.com/docs/houdini15.0/hom/hou/Node
Click here for setDisplayFlag http://www.sidefx.com/docs/houdini15.0/hom/hou/SopNode
Recommended Posts