Last active
August 14, 2021 19:48
-
-
Save FridayMarch26th/a02133830619b767f743383f6e8bf5fc to your computer and use it in GitHub Desktop.
Houdini - Extract selected node into its own network via an Object Merge
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Bung this in a shelf tool. | |
#Map it to a hotkey for bonus points. | |
#Drop me a line if anything needs fixing. :) | |
import re | |
obj = hou.node("/obj") | |
selectedNodes = hou.selectedNodes() | |
networkEditor = hou.ui.paneTabOfType(hou.paneTabType.NetworkEditor) | |
#Don't do anything if nothing's selected | |
if len(selectedNodes) > 0: | |
parent = selectedNodes[0].parent() | |
extractions = [] | |
for node in selectedNodes: | |
if isinstance(node, hou.SopNode): | |
#This isn't a very sophisticated method of removing the probable OUT node name prefex. | |
baseName = re.sub("(?i)^out_", "", node.name()) | |
extracted = obj.createNode("geo", baseName + "_extracted") | |
extracted.moveToGoodPosition() | |
merge = extracted.createNode("object_merge", "merge_" + baseName); | |
merge.setParms({"objpath1": node.path()}) | |
extractions.append(extracted.path()) | |
if len(extractions) > 0: | |
if len(extractions) == 1: | |
#If there's only one node being extracted, navigate straight to it. | |
extracted.setSelected(True) | |
networkEditor.setCurrentNode(hou.node(extractions[0]).children()[0]) | |
else: | |
#If more than one node is being extraced, head up to the parent and zoom out to reveal all. | |
parentPos = parent.position() | |
parentSize = parent.size() | |
rect = hou.BoundingRect(parentPos, parentPos + parentSize) | |
for e in extractions: | |
rect.enlargeToContain(hou.node(e).position() + hou.node(e).size()) | |
#Add a little padding | |
rect.expand([1,1]) | |
networkEditor.setCurrentNode(parent) | |
networkEditor.setVisibleBounds(rect, .1, 0, True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment