Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import hou
- def main():
- # first we make sure we are in an approved category by checking
- # against one of the selected nodes
- approvedCategories = ["Sop", "Driver", "Cop2", "Chop", "Vop", "Object",
- "Dop"]
- if hou.selectedNodes():
- node = hou.selectedNodes()[0]
- else:
- return
- curCategory = node.type().category().name()
- if curCategory in approvedCategories:
- # if we are in vops we need to reverse sort and sort from
- # the x pos not the y pos
- if curCategory == "Vop":
- direction = 0
- r = True
- else:
- direction = 1
- r = False
- # loop through the selected nodes and then sort by pos
- positions = []
- for aNode in hou.selectedNodes():
- positions.append([aNode.position()[direction], aNode])
- positions = sorted(positions, reverse=r)
- bottomNode = positions[0][1]
- if curCategory == "Sop":
- bottomNode.setDisplayFlag(True)
- bottomNode.setRenderFlag(True)
- # now we loop through the sorted list and select
- # which two nodes to connect
- if len(positions) == 2:
- nodeTwo = positions[1][1]
- nodeOne = positions[0][1]
- try:
- for aNode in nodeOne.inputs():
- if aNode is not None:
- if aNode.name() in nodeTwo.name():
- # not sure if return is the correct/ smartest way
- # to break out of the loop but break, pass, and
- # continue didnt work and return did so there it
- # is.
- return None
- nodeOne.setNextInput(nodeTwo)
- except:
- nodeOne.setFirstInput(nodeTwo)
- else:
- for i in xrange(len(positions)-1):
- nodeTwo = positions[i+1][1]
- nodeOne = positions[i][1]
- # if the curent node is a merge we can just append
- # the selection. We test to make sure that the connection
- # has not already been made though so we dont get double
- # geo. Otherwise we just set the first input.
- try:
- if nodeOne.type().name() == "merge":
- for aNode in nodeOne.inputs():
- if aNode is not None:
- if aNode.name() in nodeTwo.name():
- # not sure if return is the correct/
- # smartest way to break out of the loop
- # but break, pass, and continue didnt work
- # and return did so there it is.
- return None
- nodeOne.setNextInput(nodeTwo)
- else:
- nodeOne.setFirstInput(nodeTwo)
- except:
- pass
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement