Advertisement
mrhumbility

Layout Nodes

Jul 27th, 2015
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.00 KB | None | 0 0
  1. import hou
  2.  
  3.  
  4. def main(sortDirection, r):
  5.     # first we make sure we are in an approved category by checking
  6.     # against one of the selected nodes
  7.     approvedCategories = ["Sop", "Driver", "Cop2", "Chop", "Vop", "Object",
  8.                           "Shop", "CopNet", "Dop"]
  9.     if hou.selectedNodes():
  10.         node = hou.selectedNodes()[0]
  11.     else:
  12.         return
  13.     curCategory = node.type().category().name()
  14.     if curCategory in approvedCategories:
  15.         # if we are in vops we need to reverse sort and sort from
  16.         # the x pos not the y pos
  17.         if curCategory == "Vop":
  18.             sortDirection = 0
  19.             r = False
  20.  
  21.         # loop through the selected nodes and then sort by pos
  22.         xPositions = []
  23.         yPositions = []
  24.         positions = []
  25.         for aNode in hou.selectedNodes():
  26.             xPositions.append(aNode.position()[0])
  27.             yPositions.append(aNode.position()[1])
  28.             positions.append([aNode.position()[sortDirection], aNode])
  29.         positions = sorted(positions, reverse=r)
  30.  
  31.         # if we are in vops we want to iterate the x pos not the y pos
  32.         # xPos = sum(xPositions)/float(len(xPositions))
  33.         if sortDirection == 1:
  34.             xPos = max(set(xPositions), key=xPositions.count)
  35.         else:
  36.             xPos = min(xPositions)
  37.         yPos = max(yPositions)
  38.         for i in xrange(len(positions)):
  39.             aNode = positions[i][1]
  40.             pos = hou.Vector2(xPos, yPos)
  41.             aNode.setPosition(pos)
  42.             if sortDirection == 0:
  43.                 xPos += 2
  44.                 if curCategory != "Vop":
  45.                     yPos -= 0.5
  46.             else:
  47.                 yPos -= 1
  48.  
  49.         # bottomNode = positions[len(positions)-1][1]
  50.         # if curCategory == "Sop":
  51.         #    bottomNode.setDisplayFlag(True)
  52.         #    bottomNode.setRenderFlag(True)
  53.  
  54.         # bottomNode.setCurrent(True, clear_all_selected=True)
  55.  
  56.  
  57. def upDown():
  58.     main(1, True)
  59.  
  60.  
  61. def leftRight():
  62.     main(0,  False)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement