Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import hou
- def main():
- # well just use one of the selected nodes to get the pwd and
- # make the merge
- approvedCategories = ["Sop", "Cop2", "Driver", "Chop", "Dop"]
- if hou.selectedNodes():
- node = hou.selectedNodes()[0]
- else:
- return
- curCategory = node.type().category().name()
- nodeType = hou.ui.displayMessage(
- "Merge or Switch?", buttons=("Merge", "Switch", "Cancel"))
- if nodeType == 2:
- return None
- # Ask if we want to gather the inputs
- count = 0
- for aNode in hou.selectedNodes():
- if aNode.outputs():
- count += 1
- if count >= 1:
- result = hou.ui.displayMessage(
- "Gather connections?", buttons=("Yes", "No", "Cancel"))
- else:
- result = 1
- if result == 2:
- return None
- if curCategory in approvedCategories:
- if nodeType == 1:
- mergeNode = node.parent().createNode("switch", "switch")
- mergeNode.setColor(hou.Color([1, 1, 0.4]))
- else:
- mergeNode = node.parent().createNode("merge", "merge")
- # We will get the lowest pos from the selected nodes so that
- # we can place the merge below this. We will also take the
- # average x pos to place them merge in the middle of the
- # selection
- xPositions = []
- yPositions = []
- nodes = []
- for aNode in hou.selectedNodes():
- nodes.append([aNode.position()[0], aNode])
- xPositions.append(aNode.position()[0])
- yPositions.append(aNode.position()[1])
- xPos = sum(xPositions)/float(len(xPositions))
- # If the nodes are right on top of each other, place the merge off to
- # a side
- if xPos == max(set(xPositions), key=xPositions.count):
- xPos += 3
- yPos = min(yPositions)
- mergeNode.setPosition(hou.Vector2(xPos, yPos-1.5))
- # Sort the nodes by their x pos so it connects them to the
- # merge in the correct order
- nodes.sort()
- # Pick up all the outputs from the nodes being merged
- # and set the inputs on the merge and whatnot
- for i in xrange(len(nodes)):
- # Try to set the input. If there is some error we will
- # just skip. This happens if one of the selected nodes
- # is a rop node or a chopnet, something like that.
- if result == 0:
- for outputs in nodes[i][1].outputs():
- x = 0
- for inputs in outputs.inputs():
- if inputs is not None:
- if nodes[i][1].name() == inputs.name():
- outputs.setInput(x, mergeNode)
- x += 1
- try:
- mergeNode.setNextInput(nodes[i][1])
- except:
- pass
- # Set selections and display flags where proper
- mergeNode.setCurrent(True, clear_all_selected=True)
- if curCategory == "Sop":
- mergeNode.setDisplayFlag(True)
- mergeNode.setRenderFlag(True)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement