def popupMenu(self, *args): cmds.popupMenu() cmds.menuItem(subMenu=True, label='Show', tearOff=True, postMenuCommand=self.updateshowColorsMenu) for loopColor in self.colors: colorName = loopColor["name"] cmds.menuItem('colorMenu_%s' % colorName, label=utilMod.toTitle(colorName), checkBox=False, command=lambda x, colorName=colorName, *args: self. switchColor(colorName)) cmds.menuItem(divider=True) cmds.menuItem(subMenu=True, label="Show Only") for loopColor in self.colors: colorName = loopColor["name"] cmds.menuItem(label=utilMod.toTitle(colorName), command=lambda x, colorName=colorName, *args: self. isolateColor(colorName)) cmds.setParent('..', menu=True) cmds.menuItem('colorMenuShowAll', label="Show All Colors", command=self.showAllColors) cmds.setParent('..', menu=True) cmds.menuItem(label="Import Select Sets", command=self.importSets) cmds.menuItem(label="Export Select Sets", command=self.exportSets) cmds.menuItem(label="Delete All", command=self.deleteAllSets)
def populateSelSetButtonsMenu(self, menu, selSet, *args): extracted = self.extractInfoFromSelSet(selSet) colorName = extracted["colorName"] cmds.radioMenuItemCollection(parent=menu) for loopColor in self.colors: loopColorName = loopColor["name"] radioSelected = (colorName == loopColorName) cmds.menuItem( label=utilMod.toTitle(loopColorName), radioButton=radioSelected, command=lambda x, selSet=selSet, loopColorName=loopColorName, * args: self.renameSelectSetColor([selSet], loopColorName), parent=menu) cmds.menuItem(divider=True, parent=menu) cmds.menuItem(label='Add Selection', command=lambda *args: self.addSelection(selSet), parent=menu) cmds.menuItem(label='Remove Selection', command=lambda *args: self.removeSelection(selSet), parent=menu) cmds.menuItem(label='Update Selection', command=lambda *args: self.updateSelection(selSet), parent=menu) cmds.menuItem(divider=True, parent=menu) cmds.menuItem(label='Rename', command=lambda *args: self.turnOnRenameSetField(selSet), parent=menu) cmds.menuItem(label='Delete', command=lambda *args: self.deleteSets([selSet]), parent=menu) cmds.menuItem(label='Delete All %s' % utilMod.toTitle(colorName), command=lambda *args: self.deleteAllColorSet(colorName), parent=menu) cmds.menuItem(divider=True, parent=menu) duplicateToOtherMenu = cmds.menuItem( subMenu=True, label='Duplicate To Other Character', parent=menu, postMenuCommandOnce=True) cmds.menuItem( duplicateToOtherMenu, edit=True, postMenuCommand=lambda *args: self.populateDuplicateToOtherMenu( duplicateToOtherMenu, selSet)) cmds.setParent('..', menu=True) cmds.menuItem(label='Show Only %s' % utilMod.toTitle(colorName), command=lambda *args: self.isolateColor(colorName), parent=menu) cmds.menuItem(label='Hide %s' % utilMod.toTitle(colorName), command=lambda *args: self.hideColor(colorName), parent=menu)
def populateMenu(self, menu, *args): cmds.radioMenuItemCollection(parent=menu) for loopOption in self.multiplierValues: radioSelected = (self.multiplier == loopOption["value"]) option = loopOption["name"] cmds.menuItem(label=utilMod.toTitle(loopOption["name"]), radioButton=radioSelected, command=lambda x, option=option, *args: self. setMultiplier(option), parent=menu)
def delayedUpdateHotkeyCheck(self, name): command = cmds.button("command%s" % name, query=True, label=True) key = cmds.scrollField("key%s" % name, query=True, text=True) ctl = cmds.checkBox("ctl%s" % name, query=True, value=True) alt = cmds.checkBox("alt%s" % name, query=True, value=True) if len(key) > 1 and key not in KEYSLIST: key = key[0] cmds.scrollField("key%s" % name, edit=True, text=key) label = self.hotkeyCheck(key, ctl, alt) if label == None: label = "" cmds.text("query%s" % name, edit=True, label=label, font="plainLabelFont") if utilMod.toTitle(label) != command: cmds.text("query%s" % name, edit=True, font="boldLabelFont")
def populateDuplicateButtonMenu(self, menu, selSet, colorName): outputNameSpaces = utilMod.listAllNamespaces() uiMod.clearMenuItems(menu) if not outputNameSpaces: return for loopNameSpace in outputNameSpaces: newMenu = cmds.menuItem(subMenu=True, label=loopNameSpace, parent=menu) for loopColor in self.colors: loopColorName = loopColor["name"] if colorName != loopColorName: cmds.menuItem( label=utilMod.toTitle(loopColorName), parent=newMenu, command=lambda x, loopNameSpace=loopNameSpace, loopColorName=loopColorName, *args: self.duplicateSet( selSet, loopNameSpace, loopColorName))
def popupMenu(self): cmds.popupMenu() cmds.menuItem("autoSelectMirrorObjectsMenu", label='Auto Select Mirror Objects', checkBox=False, command=self.toggleAutoSelectMirrorObjects) cmds.menuItem("invertRulesMenu", subMenu=True, label='Invert Rules', tearOff=True) for n, loopPref in enumerate(self.INVERT_RULES_PREFS): name = loopPref["name"] if n == 6: cmds.menuItem(divider=True) cmds.menuItem('%sMenu' % name, label=utilMod.toTitle(name[11:]), command=lambda x, name=name, *args: aToolsMod. setPref(name, self.INVERT_RULES_PREFS), checkBox=aToolsMod.getPref(name, self.INVERT_RULES_PREFS)) cmds.menuItem(divider=True) cmds.menuItem("loadDefaultsInvertRulesMenu", label="Load Defaults", command=lambda *args: utilMod.loadDefaultPrefs( self.INVERT_RULES_PREFS)) cmds.setParent('..', menu=True) cmds.menuItem(divider=True) cmds.menuItem(label="Unselect Right", command=lambda *args: self.unselectMirrorObjs("right")) cmds.menuItem(label="Unselect Left", command=lambda *args: self.unselectMirrorObjs("left")) cmds.menuItem(label="Unselect Center", command=lambda *args: self.unselectMirrorObjs("center")) cmds.menuItem(divider=True) cmds.menuItem( label="Paste And Invert Cycle", command=lambda *args: self.applyMirror(pasteAndCycle=True))
def createNewSelectSet(self, setName=None, colorName=None): if colorName: G.SS_lastColorUsed = colorName setName = cmds.textField(self.createNewSetTextField, query=True, text=True) self.highlightColorSelection() tmpSetName = setName.replace(" ", "") if tmpSetName == "": return sel = cmds.ls(selection=True) if len(sel) == 0: cmds.warning("Please select some objects.") return if not self.testRepeated(sel): newSelSetName = "%s%s_%s" % (self.defaultSetName, G.SS_lastColorUsed, utilMod.toTitle(setName)) with G.aToolsBar.createAToolsNode: newSelSet = cmds.sets(sel, name=newSelSetName, text="gCharacterSet") self.showColor(G.SS_lastColorUsed) self.turnOffCreateNewSetField() self.aToolsSets.append(newSelSet) self.aToolsSets = sorted(self.aToolsSets) self.createSelSetButton(newSelSet) self.aToolsSetsDict[newSelSet] = sel self.sortSelSetButtons(newSelSet) self.blinkButton(newSelSet, 3) self.highlightSelectedButtons(newSelSet)
def populateMenu(self, menu, *args): uiMod.clearMenuItems(menu) #cmds.menuItem(label="Camera Relative", parent=menu, checkBox=self.cameraRelativeOnOff, command=self.cameraRelativeSwitch) if cmds.objExists(self.mainGroupNode): cmds.menuItem(label="Add Selection", parent=menu, command=self.addSelection) cmds.menuItem(label="Remove Selection", parent=menu, command=self.removeSelection) cmds.menuItem(label="Set Frame Range", parent=menu, command=self.setFrameRange) cmds.menuItem(divider=True, parent=menu) if cmds.objExists(self.mainGroupNode): for loopMotionTrail in self.nodeInfo.keys(): ctrl = self.nodeInfo[loopMotionTrail]["ctrlNode"] cmds.menuItem( label="Grab Offset Ctrl (%s)" % ctrl, parent=menu, command=lambda x, loopMotionTrail=loopMotionTrail, *args: self.grabOffsetCtrl(loopMotionTrail)) cmds.menuItem(divider=True, parent=menu) subMenu = cmds.menuItem(label="Preferences", subMenu=True, parent=menu, tearOff=True) #Pre pos range cmds.radioMenuItemCollection(parent=subMenu) rangeSelected = self.getPrePosRange() for loopPref in self.prePosRanges: radioSelected = (str(rangeSelected) == str(loopPref)) cmds.menuItem(label="%s" % loopPref, radioButton=radioSelected, command=lambda x, loopPref=loopPref, *args: self. savePrePosRange(loopPref), parent=subMenu) #Size cmds.menuItem(divider=True, parent=subMenu) cmds.radioMenuItemCollection(parent=subMenu) sizeSelected = self.getPrefSize() for loopSize in self.customSizes: sizeName = loopSize[0] radioSelected = (str(sizeSelected) == str(sizeName)) cmds.menuItem(label=utilMod.toTitle(sizeName), radioButton=radioSelected, command=lambda x, sizeName=sizeName, *args: self. savePrefSize(sizeName), parent=subMenu) # Keys cmds.menuItem(divider=True, parent=subMenu) cmds.radioMenuItemCollection(parent=subMenu) keySelected = self.getPrefKey() for loopPref in self.prefKeys: radioSelected = (str(keySelected) == str(loopPref)) cmds.menuItem(label="Show %s Keys" % utilMod.toTitle(loopPref), radioButton=radioSelected, command=lambda x, loopPref=loopPref, *args: self. savePrefKey(loopPref), parent=subMenu) # Camera Relative cmds.menuItem(divider=True, parent=subMenu) cmds.menuItem(label="Camera Relative", checkBox=self.cameraRelativeMode, command=self.setCameraRelativeMode, parent=subMenu) cmds.menuItem(divider=True, parent=menu) cmds.menuItem(label="Refresh", parent=menu, command=self.refreshMotionTrail)
def openGui(self, *args): winName = "commandsWindow" height = 26 commands = [] names = [] hotkeysDict = [[]] allHotkeys = hotkeys.getHotkeys() totalItems = sum(len(x) for x in allHotkeys) itemsCount = 0 aB = 0 totalColums = 2 for n, loopHotkey in enumerate(allHotkeys): if itemsCount > (totalItems / totalColums) * (aB + 1): aB += 1 hotkeysDict.append([]) itemsCount += len(loopHotkey) for loopItem in loopHotkey: hotkeysDict[aB].append(loopItem) hotkeysDict[aB][-1]["colorValue"] = self.colorValues[ self.allColors[n]] if cmds.window(winName, query=True, exists=True): cmds.deleteUI(winName) window = cmds.window(winName, title="Commands and Hotkeys") mainLayout = cmds.columnLayout(adjustableColumn=True) columnsLayout = cmds.rowColumnLayout(numberOfColumns=totalColums) for loopColumn in xrange(totalColums): parent = cmds.rowColumnLayout(numberOfColumns=7, columnSpacing=([2, 5], [3, 3], [4, 3], [5, 1], [6, 5], [7, 5]), parent=columnsLayout) cmds.text(label='Command', h=height) cmds.text(label='Ctl', h=height) cmds.text(label='Alt', h=height) cmds.text(label='Key', h=height) cmds.text(label='', h=height) cmds.text(label='Set Hotkey', h=height) cmds.text(label='Assigned to', align="left", h=height) for loopIndex, loopCommand in enumerate(hotkeysDict[loopColumn]): command = loopCommand["command"] name = loopCommand["name"] key = loopCommand["hotkey"] alt = loopCommand["alt"] ctl = loopCommand["ctl"] toolTip = loopCommand["toolTip"] color = loopCommand["colorValue"] hotkeyData = aToolsMod.loadInfoWithUser("hotkeys", name) if hotkeyData != None: key = hotkeyData[0] alt = hotkeyData[1] ctl = hotkeyData[2] cmds.button("command%s" % name, label=utilMod.toTitle(name), command=command, annotation=toolTip, h=height, bgc=color, parent=parent) cmds.checkBox('ctl%s' % name, label='', value=ctl, changeCommand=lambda x, name=name, *args: self. updateHotkeyCheck(name), h=height, parent=parent) cmds.checkBox('alt%s' % name, label='', value=alt, changeCommand=lambda x, name=name, *args: self. updateHotkeyCheck(name), h=height, parent=parent) cmds.scrollField('key%s' % name, w=80, text=key, keyPressCommand=lambda x, name=name, *args: self.updateHotkeyCheck(name), h=height, parent=parent) cmds.button(label=" ", h=height, parent=parent) self.popSpecialHotkeys(name) cmds.button( label='>', command=lambda x, name=name, command=command, *args: self. setHotkey(self.getHotkeyDict([name], [command])), h=height, parent=parent) cmds.text("query%s" % name, align="left", label=self.hotkeyCheck(key, ctl, alt), font="plainLabelFont", h=height, parent=parent) commands.append(command) names.append(name) #cmds.button(label="Set Hotkey", command=lambda *args: getHotkeyDict([name], [command], [key], [alt], [ctl], [cmd])) self.updateHotkeyCheck(name) #cmds.rowLayout(numberOfColumns=2, columnAttach=([1, 'left', 0],[2, 'right', 0]), adjustableColumn=2) cmds.button(label="Load Defaults", command=lambda *args: self.loadHotkeys(True), parent=mainLayout) cmds.button(label="Set All Hotkeys", command=lambda *args: self.setHotkey( self.getHotkeyDict(names, commands)), parent=mainLayout) cmds.showWindow(window)
def populateaToolsMenu(self, menu, button, *args): #print menu #print button #menu = menu[0] uiMod.clearMenuItems(menu) shortPrefs = PREFS[:4] for loopPref in shortPrefs: name = loopPref["name"] cmds.menuItem( '%sMenu' % name, label=utilMod.toTitle(name), command=lambda x, name=name, *args: self.setPref(name), checkBox=self.getPref(name), parent=menu) #ANIMATION CRASH RECOVERY animationCrashRecoveryPref = PREFS[4] cmds.menuItem("animationCrashRecoveryMenu", label='Animation Crash Recovery', command=lambda *args: self.setPref( animationCrashRecoveryPref["name"]), checkBox=self.getPref( animationCrashRecoveryPref["name"]), parent=menu) cmds.menuItem(optionBox=True, command=animationCrashRecovery.optionBoxWindow, parent=menu) cmds.menuItem(divider=True, parent=menu) subMenu = cmds.menuItem("prefsMenu", subMenu=True, label='Preferences', tearOff=True, parent=menu) self.commandsAndHotkeys = CommandsAndHotkeys() cmds.menuItem(label="Commands and Hotkeys", command=self.commandsAndHotkeys.openGui, parent=subMenu) cmds.menuItem(divider=True, parent=subMenu) shortPrefs = PREFS[5:] for loopPref in shortPrefs: name = loopPref["name"] cmds.menuItem( '%sMenu' % name, label=utilMod.toTitle(name), command=lambda x, name=name, *args: self.setPref(name), checkBox=self.getPref(name), parent=subMenu) cmds.menuItem(divider=True, parent=subMenu) cmds.menuItem("loadDefaultsMenu", label="Load Defaults", command=self.loadDefaultPrefs, parent=subMenu) cmds.menuItem("shelfButtonMenu", label="Create Toggle on Shelf", command=shelfButton, parent=menu) cmds.menuItem(label="Refresh", command=refreshATools, parent=menu) cmds.menuItem(label="Uninstall", command=self.uninstall, parent=menu) cmds.menuItem(divider=True) cmds.menuItem(label="Help", command=self.help, parent=menu) cmds.menuItem(label="About", command=self.about, parent=menu)
def populateMenu(self, menu, *args): uiMod.clearMenuItems(menu) tokenCustomDivider = False selObjects = cmds.ls(selection=True) if not selObjects: return channels = animMod.getAllChannels() channelList = {} tokenList = [] for n, loopObjectChannel in enumerate(channels): obj = selObjects[n] if loopObjectChannel: for loopChannel in loopObjectChannel: tokens = animMod.getTokens(obj, loopChannel) if tokens and len(tokens) > 1: if not channelList.has_key(loopChannel): channelList[loopChannel] = { "objects": [], "tokens": [] } channelList[loopChannel]["objects"].append(obj) channelList[loopChannel]["tokens"].append(tokens) for loopChannelList in channelList: newMenu = cmds.menuItem(subMenu=True, label=utilMod.toTitle(loopChannelList), parent=menu) objects = channelList[loopChannelList]["objects"] tokens = channelList[loopChannelList]["tokens"] mergedTokens = utilMod.mergeLists(tokens) tokenDict = [] for loopMergedTokens in mergedTokens: tokenDict.append({"token": loopMergedTokens, "objects": []}) for n, loopObject in enumerate(objects): t = tokens[n] if loopMergedTokens in t: tokenDict[-1]["objects"].append(loopObject) cmds.radioMenuItemCollection(parent=menu) for n, loopTokenDict in enumerate(tokenDict): tokenCustomDivider = True token = loopTokenDict["token"] objects = loopTokenDict["objects"] selectedList = [ cmds.getAttr("%s.%s" % (loopObj, loopChannelList)) for loopObj in objects ] radioSelected = False if len(set(selectedList)) == 1: if selectedList[0] == n: radioSelected = True cmds.menuItem(label=utilMod.toTitle(token), radioButton=radioSelected, parent=newMenu, command=lambda x, objects=objects, channel= loopChannelList, token=token, *args: self. spaceSwitch([objects, channel, token])) #ALL KEYS cmds.menuItem(divider=True, parent=newMenu) newMenu = cmds.menuItem(subMenu=True, label='All Keys', parent=newMenu) cmds.radioMenuItemCollection(parent=newMenu) for n, loopTokenDict in enumerate(tokenDict): token = loopTokenDict["token"] objects = loopTokenDict["objects"] selectedList = [ cmds.getAttr("%s.%s" % (loopObj, loopChannelList)) for loopObj in objects ] radioSelected = False if len(set(selectedList)) == 1: if selectedList[0] == n: radioSelected = True cmds.menuItem(label=utilMod.toTitle(token), radioButton=radioSelected, parent=newMenu, command=lambda x, objects=objects, channel= loopChannelList, token=token, *args: self. spaceSwitch([objects, channel, token], all=True)) # CUSTOM SWITCH allCustomSwitch = aToolsMod.loadInfoWithUser("spaceSwitch", "customSwitch") or [] channelboxSelObjs = animMod.channelBoxSel() if channelboxSelObjs: obj = ".".join(channelboxSelObjs[0].split(".")[:-1]) selectedSwitch = [ loopAttr.split(".")[-1] for loopAttr in channelboxSelObjs if utilMod.isDynamic(obj, loopAttr.split(".")[-1]) ] if len(selectedSwitch ) > 0 and selectedSwitch not in allCustomSwitch: allCustomSwitch.append(selectedSwitch) aToolsMod.saveInfoWithUser("spaceSwitch", "customSwitch", allCustomSwitch) # populate menu if len(allCustomSwitch) > 0: divider = False customSwitchesAdded = [] customSwitchesMenu = [] for loopObj in selObjects: for loopCustomSwitch in sorted(allCustomSwitch, key=len, reverse=True): if len(loopCustomSwitch) == 0: continue switchName = utilMod.getNameSpace([loopObj ])[1][0].split(".")[0] exit = False for loopAttr in loopCustomSwitch: objAttr = "%s.%s" % (loopObj, loopAttr) if not cmds.objExists(objAttr): exit = True break if exit: continue customSwitchesMenu.append({ "objects": [loopObj], "switches": loopCustomSwitch }) for loopMenu in customSwitchesMenu[:-1]: if loopObj in loopMenu["objects"] and len( loopCustomSwitch) < len( loopMenu["switches"] ) and utilMod.listIntersection( loopMenu["switches"], loopCustomSwitch) == loopCustomSwitch: customSwitchesMenu.pop() break if loopCustomSwitch == loopMenu["switches"]: loopMenu["objects"].append(loopObj) customSwitchesMenu.pop() break for loopSwitchMenu in customSwitchesMenu: objects = loopSwitchMenu["objects"] switches = loopSwitchMenu["switches"] switchName = ", ".join( list(set(utilMod.getNameSpace(objects)[1]))) if not divider and tokenCustomDivider: divider = cmds.menuItem(divider=True, parent=menu) cmds.radioMenuItemCollection(parent=menu) newMenu = cmds.menuItem(subMenu=True, label=switchName, parent=menu) radioSelected = [] for loopCustomSwitchAttr in switches: switchAttr = loopCustomSwitchAttr.split(".")[-1] objAttr = "%s.%s" % (objects[0], switchAttr) minValue = cmds.addAttr(objAttr, query=True, minValue=True) maxValue = cmds.addAttr(objAttr, query=True, maxValue=True) currValue = cmds.getAttr(objAttr) radioSelected.append((currValue == maxValue)) cmds.menuItem( label=switchAttr, radioButton=radioSelected[-1], parent=newMenu, command=lambda x, objects=objects, switchAttr= switchAttr, switches=switches, *args: self.spaceSwitch( [objects, switchAttr, switches], mode="custom")) switchAttr = "message" radioSelected = (list(set(radioSelected)) == [False]) cmds.menuItem( label="None", radioButton=radioSelected, parent=newMenu, command=lambda x, objects=objects, switchAttr=switchAttr, switches=switches, *args: self.spaceSwitch( [objects, switchAttr, switches], mode="custom")) #ALL KEYS cmds.menuItem(divider=True, parent=newMenu) allMenu = cmds.menuItem(subMenu=True, label='All Keys', parent=newMenu) radioSelected = [] cmds.radioMenuItemCollection(parent=menu) for loopCustomSwitchAttr in switches: switchAttr = loopCustomSwitchAttr.split(".")[-1] objAttr = "%s.%s" % (objects[0], switchAttr) minValue = cmds.addAttr(objAttr, query=True, minValue=True) maxValue = cmds.addAttr(objAttr, query=True, maxValue=True) currValue = cmds.getAttr(objAttr) radioSelected.append((currValue == maxValue)) cmds.menuItem(label=switchAttr, radioButton=radioSelected[-1], parent=allMenu, command=lambda x, objects=objects, switchAttr =switchAttr, switches=switches, *args: self. spaceSwitch([objects, switchAttr, switches], all=True, mode="custom")) switchAttr = "message" radioSelected = (list(set(radioSelected)) == [False]) cmds.menuItem(label="None", radioButton=radioSelected, parent=allMenu, command=lambda x, objects=objects, switchAttr= switchAttr, switches=switches, *args: self. spaceSwitch([objects, switchAttr, switches], all=True, mode="custom")) #DELETE cmds.menuItem(label="Remove", parent=newMenu, command=lambda x, switches=switches, *args: self. removeCustomSwitch(switches))