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 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)