Merge Nodes-Houdini Python Practice

What is this?

Houdini Python practice. It sounds like a redevelopment of the wheel, but the content is "connect the selected SOP node to Merge".

script

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 merge_node.png Like this. A Merge node is created, and the selected nodes are connected to it in a batch.

Note

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.

reference

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

Merge Nodes-Houdini Python Practice
Beginners practice Python
Predictive Statistics (Practice Classification) Python
Introducing Python in Practice (PiP)
What's new in python3.9 Merge dictionaries
Practice! !! Introduction to Python (Type Hints)
Python
Predictive Statistics (Practice Simple Regression) Python
Algorithm (segment tree) in Python (practice)
(Bad) practice of using this in Python
Getting Started with Python Web Scraping Practice
AtCoder Library Practice Contest Participation Report (Python)
Predictive statistics (practice edition multiple regression) python
Python 3.9 dict merge (`|`) seems to be useful
Getting Started with Python Web Scraping Practice
Practice web scraping with Python and Selenium
[python] Read html file and practice scraping