def getNonKeyedAttrs(self, animObjects): objAttrs = animMod.getAllChannels(animObjects, changed=True, withAnimation=False) nonKeyedObjAttrs = [] for n, loopObj in enumerate(animObjects): loopObjAttrs = objAttrs[n] if not loopObjAttrs: continue for loopAttr in loopObjAttrs: if loopAttr in self.ignoreAttrs: continue objAttr = "%s.%s"%(loopObj, loopAttr) if not cmds.objExists(objAttr): continue frameCount = cmds.keyframe(objAttr, query=True, keyframeCount=True) if frameCount <= 0: nonKeyedObjAttrs.append(objAttr) return nonKeyedObjAttrs
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))