暫無描述
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

alignNodes.py 1.3KB

12345678910111213141516171819202122232425262728293031323334353637
  1. import nuke
  2. import alignNodes
  3. class alignNodes(KellerNukePlugin):
  4. def configurePlugin(self):
  5. #self.menu = nuke.menu("Nuke")
  6. #self.m = menubar.addMenu("&Edit")
  7. nuke.menu('Nuke').addCommand('Edit/Node/Align/horizontally', 'alignNodes.alignNodesExec( nuke.selectedNodes(), direction="x")', 'alt+x')
  8. nuke.menu('Nuke').addCommand('Edit/Node/Align/vertically', 'alignNodes.alignNodesExec( nuke.selectedNodes(), direction="y")', 'alt+y')
  9. def unconfigurePlugin(self):
  10. self.menu.removeItem("alignNodes")
  11. pass
  12. def alignNodesExec(nodes, direction = 'x'):
  13. '''Align nodes either horizontally or vertically.'''
  14. direction = direction.lower()
  15. if len(nodes) < 2:
  16. return
  17. if direction not in ('x', 'y'):
  18. raise ValueError, 'direction argument must be x or y'
  19. if direction == 'x':
  20. positions = [float(n['xpos'].value() + n.screenWidth() * .5) for n in nodes]
  21. else:
  22. positions = [float(n['ypos'].value() + n.screenHeight() * .5) for n in nodes]
  23. avrg = sum(positions) / len(positions)
  24. for n in nodes:
  25. if direction == 'x':
  26. for n in nodes:
  27. n.setXpos(int(avrg - n.screenWidth() * .5))
  28. else:
  29. for n in nodes:
  30. n.setYpos(int(avrg - n.screenHeight() * .5))
  31. return avrg