3dcampbell

maya qss buttons2

Nov 7th, 2012
424
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.29 KB | None | 0 0
  1. # Created by Don Campbell with guidence from Justin Isreal.
  2.  
  3. # This tool will take prefixed ( currently hard coded to "qss") and
  4. # dynamically create a window and buttons to select the set and key avaiable
  5. # animation channels.
  6.  
  7. # Possible updates window to input prefix and or window that simply puts all
  8. # user created quick select sets in their own window for easy activation.
  9.  
  10. import maya.cmds as cmds
  11. from functools import partial
  12.  
  13.    
  14. def myfunc2(inst=None, thing=None, arg=None):
  15.     # thing will be the button name
  16.     label = cmds.button(thing, query=True, label=True)
  17.     # look up the selection set from the button name
  18.     quickSel = inst.buttons[thing]
  19.     cmds.select(quickSel, replace=True)
  20.     # used a manual KEY ALL because I was finding a
  21.     # bug with the selection of the first button and
  22.     # the channelBox not seeing any items in time
  23.     for node in cmds.ls(sl=True, l=True):
  24.         for attr in cmds.listAttr(node, r=True, w=True, k=True, v=True):
  25.             cmds.setKeyframe('%s.%s' % (node, attr))
  26.  
  27.  
  28. class ui():
  29.     def __init__(self, winName="winTheWindow"):
  30.         self.winTitle = "The Window"
  31.         self.winName = winName
  32.         # save our dynamic buttons here with any meta data we want
  33.         self.buttons = {}
  34.  
  35.     def create(self,setList):
  36.         if cmds.window(self.winName, exists=True):
  37.             cmds.deleteUI(self.winName)
  38.  
  39.         cmds.window(self.winName, title=self.winTitle)
  40.         self.mainCol = cmds.columnLayout( adjustableColumn=True )
  41.        
  42.         for i in setList:
  43.             name = "%s Key ALL" % i
  44.             button = cmds.button(label=name)
  45.             # pass the button name as the "thing"
  46.             cmds.button(button, e=True, c=partial(myfunc2, self, button))
  47.             # save our button in a dict, with the select set as the value
  48.             self.buttons[button] = i  
  49.            
  50.         cmds.showWindow( self.winName )
  51.         cmds.window(self.winName, edit=True, widthHeight=[250,450])
  52.  
  53. #define the prefix
  54. prefix = "qss"
  55. setnames = []
  56.  
  57. #select all the object sets
  58. Slist = cmds.ls(sets = True)
  59. #loop through and append only the set names we want.
  60. for b in Slist:
  61.     if b.startswith(prefix):
  62.         print b
  63.         setnames.append(b)
  64.  
  65.  
  66. # create the window
  67. inst = ui()
  68. inst.create(setnames)
Advertisement
Add Comment
Please, Sign In to add comment