def copy(self, *args): #print "copy" self.selection = cmds.ls(selection=True) if len(self.selection) < 1: cmds.warning("You need to select at least 2 objects.") return if len(self.selection) == 1: self.copyWorld() return if len(self.selection) > 20: message = "Too many objects selected, continue?" confirm = cmds.confirmDialog( title='Confirm', message=message, button=['Yes','No'], defaultButton='Yes', cancelButton='No', dismissString='No' ) if confirm != 'Yes': return cmds.refresh(suspend=True) cmds.undoInfo(stateWithoutFlush=False) self.flushCopyCache(force=True) self.scriptJob() self.sourceObjs = self.selection[0:-1] self.targetObj = self.selection[-1] selObjects = utilMod.getNameSpace(self.selection)[1] self.locators = [] self.locatorGroup = animMod.group(name=self.locatorGroupName) G.aToolsBar.align.align([self.locatorGroup], self.targetObj) self.locators.append(self.locatorGroup) for loopObj in self.sourceObjs: nameSpace = utilMod.getNameSpace([loopObj]) loopSelName = "%s_%s"%(nameSpace[0][0], nameSpace[1][0]) locatorName = "fakeConstrain_%s"%loopSelName locator = animMod.createNull(locatorName) self.locators.append(locator) with G.aToolsBar.createAToolsNode: cmds.parent(locator, self.locatorGroup) G.aToolsBar.align.align([locator], loopObj) matrix = cmds.xform(locator, query=True, matrix=True) self.copyCache.append(matrix) self.clearLocators() cmds.select(self.selection) cmds.iconTextButton("fakeConstrainBtn", edit=True, image= uiMod.getImagePath("specialTools_fake_constrain_active"), highlightImage= uiMod.getImagePath("specialTools_fake_constrain_active copy")) cmds.refresh(suspend=False) cmds.undoInfo(stateWithoutFlush=True)
def duplicateSet(self, selSets, outputNameSpace, newColor): cmds.waitCursor(state=True) selSetsData = self.getSetsData(selSets) selSets = selSetsData[0] contents = selSetsData[1] inputNameSpaces = [] newSelSets = [] separator = ":" for loopContents in contents: nameSpaces = utilMod.getNameSpace(loopContents)[0] for loopNameSpace in nameSpaces: if loopNameSpace[:-1] not in inputNameSpaces: inputNameSpaces.append(loopNameSpace[:-1]) for inputNameSpace in inputNameSpaces: selSetsStr = str(selSetsData) selSetsData = eval( selSetsStr.replace("%s%s" % (inputNameSpace, separator), "%s%s" % (outputNameSpace, separator))) for loopSet in selSets: newSelSets.append(self.getRenamedColor(loopSet, newColor)) selSetsData[0] = newSelSets self.createSetsFromData(selSetsData) cmds.waitCursor(state=False)
def duplicateSet(self, selSets, outputNameSpace, newColor): cmds.waitCursor(state=True) selSetsData = self.getSetsData(selSets) selSets = selSetsData[0] contents = selSetsData[1] inputNameSpaces = [] newSelSets = [] separator = ":" for loopContents in contents: nameSpaces = utilMod.getNameSpace(loopContents)[0] for loopNameSpace in nameSpaces: if loopNameSpace[:-1] not in inputNameSpaces: inputNameSpaces.append(loopNameSpace[:-1]) for inputNameSpace in inputNameSpaces: selSetsStr = str(selSetsData) selSetsData = eval(selSetsStr.replace("%s%s"%(inputNameSpace, separator), "%s%s"%(outputNameSpace, separator))) for loopSet in selSets: newSelSets.append(self.getRenamedColor(loopSet, newColor)) selSetsData[0] = newSelSets self.createSetsFromData(selSetsData) cmds.waitCursor(state=False)
def remapNamespaces(self, *args): winName = "remapNamespacesWindow" if cmds.window(winName, query=True, exists=True): cmds.deleteUI(winName) window = cmds.window( winName, title = "Remap Namespaces") cmds.columnLayout(adjustableColumn=True) cmds.rowColumnLayout( numberOfColumns=3) animData = aToolsMod.loadInfoWithUser("copyPasteAnim", "animData") inputNameSpaces = list(set(utilMod.getNameSpace(animData["objects"])[0])) outputNameSpaces = utilMod.listAllNamespaces() for loopNameSpace in inputNameSpaces: nameSpace = loopNameSpace[:-1] eval("cmds.text('input%s', align='right', w=150, h=26, label='%s: ')"%(nameSpace, nameSpace)) eval("cmds.textField('output%s', w=150, h=26, text='%s')"%(nameSpace, nameSpace)) eval("cmds.button('output%s', w=26, h=26, label='...')"%(nameSpace)) if outputNameSpaces: cmds.popupMenu(button=1) for loopOutput in outputNameSpaces: cmds.menuItem ("menu%s"%loopOutput, label=str(loopOutput), command=lambda x, loopOutput=loopOutput, nameSpace=nameSpace, *args: self.setOutputValue(loopOutput, nameSpace)) cmds.setParent( '..' ) cmds.button(label="Paste Animation in Place", command=lambda *args: self.remapAndPasteAnimation(animData, inputNameSpaces, pasteInPlace=True)) cmds.button(label="Paste Original Animation", command=lambda *args: self.remapAndPasteAnimation(animData, inputNameSpaces, pasteInPlace=False)) cmds.showWindow( window )
def setAttribute(obj, attr, value): sel = cmds.ls(selection=True) if not sel and G.currNameSpace == None: cmds.warning("Please select any controller.") return if sel: nameSpaces = utilMod.getNameSpace(sel) G.currNameSpace = nameSpaces[0][0] cmds.setAttr("%s%s.%s" % (G.currNameSpace, obj, attr), value)
def setAttribute(obj, attr, value): sel = cmds.ls(selection=True) if not sel and G.currNameSpace == None: cmds.warning("Please select any controller.") return if sel: nameSpaces = utilMod.getNameSpace(sel) G.currNameSpace = nameSpaces[0][0] cmds.setAttr("%s%s.%s"%(G.currNameSpace, obj, attr), value)
def selectCtrlGroup(g): sel = cmds.ls(selection=True) if not sel and G.currNameSpace == None: cmds.warning("Please select any controller.") return if sel: nameSpaces = utilMod.getNameSpace(sel) G.currNameSpace = nameSpaces[0][0] cmds.select(clear=True) nameSpaceAndObjs = ["%s%s" % (G.currNameSpace, loopObj) for loopObj in g] cmds.select(nameSpaceAndObjs)
def selectCtrlGroup(g): sel = cmds.ls(selection=True) if not sel and G.currNameSpace == None: cmds.warning("Please select any controller.") return if sel: nameSpaces = utilMod.getNameSpace(sel) G.currNameSpace = nameSpaces[0][0] cmds.select(clear=True) nameSpaceAndObjs = ["%s%s"%(G.currNameSpace, loopObj) for loopObj in g] cmds.select(nameSpaceAndObjs)
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))
def create(self, *args): img = cmds.iconTextButton("TempCustomPivotBtn", query=True, image=True) onOff = (img[-10:-4] == "active") if onOff: self.clear() cmds.select(self.sel) return cmds.undoInfo(openChunk=True) cmds.undoInfo(closeChunk=True) cmds.undoInfo(openChunk=True) cmds.undoInfo(closeChunk=True) cmds.undoInfo(openChunk=True) cmds.undoInfo(closeChunk=True) cmds.undoInfo(openChunk=True) self.clear() getCurves = animMod.getAnimCurves() animCurves = getCurves[0] getFrom = getCurves[1] if animCurves: keyTimes = animMod.getTarget("keyTimes", animCurves, getFrom) self.sel = cmds.ls(selection=True) if not self.sel: return cmds.iconTextButton("TempCustomPivotBtn", edit=True, image= uiMod.getImagePath("specialTools_create_temp_custom_pivot_active"), highlightImage= uiMod.getImagePath("specialTools_create_temp_custom_pivot_active")) targetObj = self.sel[-1] aToolsMod.saveInfoWithScene(self.STORE_NODE, self.CTRLS, self.sel) currentFrame = cmds.currentTime(query=True) aToolsMod.saveInfoWithScene(self.STORE_NODE, self.CURRENTFRAME, currentFrame) locators = [] for loopSel in self.sel: nameSpace = utilMod.getNameSpace([loopSel]) loopSelName = "%s_%s"%(nameSpace[0][0], nameSpace[1][0]) locatorName = "tempCustomPivot_%s"%loopSelName locator = animMod.createNull(locatorName) locators.append(locator) G.aToolsBar.align.align([locator], loopSel) locatorGroup = "tempCustomPivot_group" animMod.group(name=locatorGroup) G.aToolsBar.align.align([locatorGroup], targetObj) with G.aToolsBar.createAToolsNode: cmds.parent(locators, locatorGroup) cmds.select(locatorGroup, replace=True) locators.append(locatorGroup) aToolsMod.saveInfoWithScene(self.STORE_NODE, self.LOCATORS, locators) #parent ctrls to locator constraints = ["%s_tempCustomPivot_constraint"%loopConstraint for loopConstraint in self.sel] aToolsMod.saveInfoWithScene(self.STORE_NODE, self.CONSTRAINTS, constraints) for n, loopSel in enumerate(self.sel): with G.aToolsBar.createAToolsNode: cmds.parentConstraint(locators[n], loopSel, name=constraints[n], maintainOffset=True) constraintNode = "%s.blendParent1"%loopSel if not cmds.objExists(constraintNode): continue cmds.setKeyframe(constraintNode) if keyTimes: for loopTime in keyTimes[0]: cmds.setKeyframe("%s.tx"%locatorGroup, time=(loopTime,loopTime)) if loopTime != currentFrame: cmds.setKeyframe(constraintNode, time=(loopTime,loopTime), value=0) #enter edit mode cmds.setToolTo(cmds.currentCtx()) cmds.ctxEditMode() #scriptjob cmds.scriptJob(runOnce = True, killWithScene = True, event =('SelectionChanged', self.scriptJob_SelectionChanged))
def paste(self, type="onlyKeys"): cmds.refresh(suspend=True) selObjects = utilMod.getNameSpace(self.selection)[1] self.locators = [] if self.targetObj != "world": #CREATE self.locatorGroup = animMod.group(name=self.locatorGroupName) for n, loopObj in enumerate(self.sourceObjs): nameSpace = utilMod.getNameSpace([loopObj]) loopSelName = "%s_%s"%(nameSpace[0][0], nameSpace[1][0]) locatorName = "fakeConstrain_%s"%loopSelName locator = animMod.createNull(locatorName) self.locators.append(locator) with G.aToolsBar.createAToolsNode: cmds.parent(locator, self.locatorGroup) self.locators.append(self.locatorGroup) currFrame = cmds.currentTime(query=True) getCurves = animMod.getAnimCurves() animCurves = getCurves[0] getFrom = getCurves[1] if animCurves: keysSel = animMod.getTarget("keysSel", animCurves, getFrom) keysSel = utilMod.mergeLists(keysSel) if keysSel == []: keysSel = [currFrame] else: keysSel = [currFrame] frames = keysSel if type == "allFrames": frameRange = animMod.getTimelineRange(float=False) frames = list(range(int(frameRange[0]),int(frameRange[1]))) if self.targetObj != "world": G.aToolsBar.align.align([self.locatorGroup], self.targetObj, frames=frames) for n, loopObj in enumerate(self.sourceObjs): matrix = self.copyCache[n] if self.targetObj != "world": cmds.xform(self.locators[n], matrix=matrix) G.aToolsBar.align.align([loopObj], self.locators[n], frames=frames, showProgress=True) else: for loopFrame in frames: cmds.currentTime(loopFrame) cmds.xform(loopObj, ws=True, matrix=matrix) cmds.currentTime(currFrame) for loopFrame in frames: for loopAttr in ["translate", "rotate"]: breakdown = (loopFrame not in keysSel) cmds.keyframe(loopObj, edit=True, attribute=loopAttr, time=(loopFrame, loopFrame), breakdown=breakdown) if self.targetObj != "world": self.clearLocators() cmds.select(self.selection) cmds.refresh(suspend=False)