Beispiel #1
0
    def setMode(self, onOff):
        
        utilMod.killScriptJobs("G.microTransformScriptJobs")
                
        if onOff:
            
            self.rotationOrientMode         = cmds.manipRotateContext('Rotate', query=True, mode=True)
            cmds.manipRotateContext('Rotate', edit=True, mode=2)#gimbal
            #update values on turning on
            self.addMicroTransform()
            
            G.microTransformScriptJobs = []
            # get the current selected object values
            G.microTransformScriptJobs.append(cmds.scriptJob(runOnce = False, killWithScene = False, event =('SelectionChanged', self.addMicroTransform ))) 
            G.microTransformScriptJobs.append(cmds.scriptJob(runOnce = False, killWithScene = False, event =('timeChanged', self.updateValues )))
            G.microTransformScriptJobs.append(cmds.scriptJob(runOnce = False, killWithScene = False, event =('Undo', self.updateValues ))) 
            G.microTransformScriptJobs.append(cmds.scriptJob(runOnce = False, killWithScene = False, event =('Redo', self.updateValues ))) 
            G.microTransformScriptJobs.append(cmds.scriptJob(runOnce = False, killWithScene = False, event =('DragRelease', self.release ))) 
            

            
            #print "microTransform is ON."
            
        else:
            cmds.manipRotateContext('Rotate', edit=True, mode=self.rotationOrientMode)
            self.removeMicroTransform()
Beispiel #2
0
 def setAutoSelectMirrorObjects(self, onOff):
     
     utilMod.killScriptJobs("G.mirrorScriptJobs")
             
     if onOff:
         self.autoSelectMirrorObjects()   
         G.mirrorScriptJobs.append(cmds.scriptJob(runOnce = False, killWithScene = False, event =('SelectionChanged', self.autoSelectMirrorObjects )))  
def togglejumpToSelectedKey(onOff):
    utilMod.killScriptJobs("G.jumpToSelectedKeyScriptJobs")
    
    if onOff:
        G.jumpToSelectedKeyScriptJobs.append(cmds.scriptJob(runOnce = False, killWithScene = False,  event =('SelectionChanged',  animMod.jumpToSelectedKey)) )

        animMod.jumpToSelectedKey()
def toggleframePlaybackRange(onOff):
    utilMod.killScriptJobs("G.framePlaybackRangeScriptJobs")
    
    if onOff:
        G.framePlaybackRangeScriptJobs.append(cmds.scriptJob(runOnce = False, killWithScene = False,  event =('ToolChanged',  framePlaybackRangeFn)) )
        G.framePlaybackRangeScriptJobs.append(cmds.scriptJob(runOnce = False, killWithScene = False,  event =('SelectionChanged',  framePlaybackRangeFn)) )
        
        framePlaybackRangeFn()
Beispiel #5
0
    def switch(self, onOff):

        utilMod.killScriptJobs("G.autoSmartSnapKeysJobs")

        if onOff:
            G.autoSmartSnapKeysJobs.append(
                cmds.scriptJob(runOnce=False,
                               killWithScene=False,
                               event=('timeChanged', self.smartSnapKeys)))
Beispiel #6
0
def togglejumpToSelectedKey(onOff):
    utilMod.killScriptJobs("G.jumpToSelectedKeyScriptJobs")

    if onOff:
        G.jumpToSelectedKeyScriptJobs.append(
            cmds.scriptJob(runOnce=False,
                           killWithScene=False,
                           event=('SelectionChanged',
                                  animMod.jumpToSelectedKey)))

        animMod.jumpToSelectedKey()
Beispiel #7
0
 def switch(self, onOff):
        
     utilMod.killScriptJobs("G.selectionCounterScriptJobs")
     cmds.iconTextButton("selectionCounterButton", edit=True, visible=False)
 
     if onOff:
         cmds.iconTextButton("selectionCounterButton", edit=True, visible=True)
         
         G.selectionCounterScriptJobs.append(cmds.scriptJob(runOnce = False, killWithScene = False, event =('SelectionChanged', self.update )))
     
     self.update()
Beispiel #8
0
    def setAutoSelectMirrorObjects(self, onOff):

        utilMod.killScriptJobs("G.mirrorScriptJobs")

        if onOff:
            self.autoSelectMirrorObjects()
            G.mirrorScriptJobs.append(
                cmds.scriptJob(runOnce=False,
                               killWithScene=False,
                               event=('SelectionChanged',
                                      self.autoSelectMirrorObjects)))
Beispiel #9
0
 def switch(self, onOff):
        
     utilMod.killScriptJobs("G.selectionCounterScriptJobs")
     cmds.iconTextButton("selectionCounterButton", edit=True, visible=False)
 
     if onOff:
         cmds.iconTextButton("selectionCounterButton", edit=True, visible=True)
         
         G.selectionCounterScriptJobs.append(cmds.scriptJob(runOnce = False, killWithScene = False, event =('SelectionChanged', self.update )))
     
     self.update()
Beispiel #10
0
def toggleframePlaybackRange(onOff):
    utilMod.killScriptJobs("G.framePlaybackRangeScriptJobs")

    if onOff:
        G.framePlaybackRangeScriptJobs.append(
            cmds.scriptJob(runOnce=False,
                           killWithScene=False,
                           event=('ToolChanged', framePlaybackRangeFn)))
        G.framePlaybackRangeScriptJobs.append(
            cmds.scriptJob(runOnce=False,
                           killWithScene=False,
                           event=('SelectionChanged', framePlaybackRangeFn)))

        framePlaybackRangeFn()
Beispiel #11
0
 def switch(self, onOff):
 
     utilMod.killScriptJobs("G.tumbleOnObjectsScriptJobs")
     
     if onOff:
         cmds.tumbleCtx ("tumbleContext", edit=True, localTumble=0)
         #scriptJob   
         G.tumbleOnObjectsScriptJobs.append(cmds.scriptJob(runOnce = False, killWithScene = False, event =('DragRelease', self.update )))
         G.tumbleOnObjectsScriptJobs.append(cmds.scriptJob(runOnce = False, killWithScene = False, event =('SelectionChanged', self.update )))
         G.tumbleOnObjectsScriptJobs.append(cmds.scriptJob(runOnce = False, killWithScene = False, event =('timeChanged', self.update )))
         
         self.update()
         
     else:
         cmds.tumbleCtx ("tumbleContext", edit=True, localTumble=self.currentLocalTumble)
Beispiel #12
0
    def setMode(self, onOff):

        utilMod.killScriptJobs("G.microTransformScriptJobs")

        if onOff:

            self.rotationOrientMode = cmds.manipRotateContext('Rotate',
                                                              query=True,
                                                              mode=True)
            cmds.manipRotateContext('Rotate', edit=True, mode=2)  #gimbal
            #update values on turning on
            self.addMicroTransform()

            G.microTransformScriptJobs = []
            # get the current selected object values
            G.microTransformScriptJobs.append(
                cmds.scriptJob(runOnce=False,
                               killWithScene=False,
                               event=('SelectionChanged',
                                      self.addMicroTransform)))
            G.microTransformScriptJobs.append(
                cmds.scriptJob(runOnce=False,
                               killWithScene=False,
                               event=('timeChanged', self.updateValues)))
            G.microTransformScriptJobs.append(
                cmds.scriptJob(runOnce=False,
                               killWithScene=False,
                               event=('Undo', self.updateValues)))
            G.microTransformScriptJobs.append(
                cmds.scriptJob(runOnce=False,
                               killWithScene=False,
                               event=('Redo', self.updateValues)))
            G.microTransformScriptJobs.append(
                cmds.scriptJob(runOnce=False,
                               killWithScene=False,
                               event=('DragRelease', self.release)))

            #print "microTransform is ON."

        else:
            cmds.manipRotateContext('Rotate',
                                    edit=True,
                                    mode=self.rotationOrientMode)
            self.removeMicroTransform()
Beispiel #13
0
    def switch(self, onOff):
        
        
        self.removeMessages() 
        utilMod.killScriptJobs("G.animationCrashRecoveryScriptJobs")  
                
        if onOff:

            #self.saveAllAnimationData(update=True)
            self.addAnimSceneMessages()
            self.addNodeMessages()  
            self.addMdgMessages()            
            G.animationCrashRecoveryScriptJobs.append(cmds.scriptJob(runOnce = False, killWithScene = False, event =('SelectionChanged', self.addNodeMessages )))
            
            
            self.recommendSaving(True)
            #self.recommendSaving(False)#TMP
            
        else:
            G.deferredManager.removeFromQueue("ACR")
            self.setLed("off")
Beispiel #14
0
class Mirror(object):

    utilMod.killScriptJobs("G.mirrorScriptJobs")

    def __init__(self):

        self.INVERT_RULES_PREFS = [{
            "name": "invertRulesMirrorObjsTranslateX",
            "default": True
        }, {
            "name": "invertRulesMirrorObjsTranslateY",
            "default": False
        }, {
            "name": "invertRulesMirrorObjsTranslateZ",
            "default": False
        }, {
            "name": "invertRulesMirrorObjsRotateX",
            "default": False
        }, {
            "name": "invertRulesMirrorObjsRotateY",
            "default": False
        }, {
            "name": "invertRulesMirrorObjsRotateZ",
            "default": False
        }, {
            "name": "invertRulesCenterObjsTranslateX",
            "default": True
        }, {
            "name": "invertRulesCenterObjsTranslateY",
            "default": False
        }, {
            "name": "invertRulesCenterObjsTranslateZ",
            "default": False
        }, {
            "name": "invertRulesCenterObjsRotateX",
            "default": False
        }, {
            "name": "invertRulesCenterObjsRotateY",
            "default": True
        }, {
            "name": "invertRulesCenterObjsRotateZ",
            "default": True
        }]

    def start(self):
        mod = uiMod.getModKeyPressed()

        if mod == "shift":
            self.selectMirrorObjs(True)
        elif mod == "ctrl":
            self.selectMirrorObjs(False)
        else:
            sel = cmds.ls(selection=True)
            if sel: self.applyMirror()
            else: self.toggleAutoSelectMirrorObjects()

    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 toggleAutoSelectMirrorObjects(self, *args):

        onOff = not cmds.menuItem(
            "autoSelectMirrorObjectsMenu", query=True, checkBox=True)
        if args: onOff = not onOff  #if checkbox pressed

        if onOff:
            cmds.iconTextButton(
                "mirrorBtn",
                edit=True,
                image=uiMod.getImagePath("specialTools_mirror_active"),
                highlightImage=uiMod.getImagePath(
                    "specialTools_mirror_active"))
        else:
            cmds.iconTextButton(
                "mirrorBtn",
                edit=True,
                image=uiMod.getImagePath("specialTools_mirror"),
                highlightImage=uiMod.getImagePath("specialTools_mirror copy"))

        self.setAutoSelectMirrorObjects(onOff)
        if not args:
            cmds.menuItem("autoSelectMirrorObjectsMenu",
                          edit=True,
                          checkBox=onOff)

    def setAutoSelectMirrorObjects(self, onOff):

        utilMod.killScriptJobs("G.mirrorScriptJobs")

        if onOff:
            self.autoSelectMirrorObjects()
            G.mirrorScriptJobs.append(
                cmds.scriptJob(runOnce=False,
                               killWithScene=False,
                               event=('SelectionChanged',
                                      self.autoSelectMirrorObjects)))

    def autoSelectMirrorObjects(self):
        sel = cmds.ls(selection=True)
        if sel: self.selectMirrorObjs(add=True, lastObj=sel[-1])

    def getInvertRules(self):

        invertRules = []

        for loopPref in self.INVERT_RULES_PREFS:
            name = loopPref["name"]
            pref = aToolsMod.getPref(name, self.INVERT_RULES_PREFS)
            mode = name[11:]

            if pref: invertRules.append(mode)

        return invertRules

    def mirrorInvert(self, aCurve, isCenterCurve, invertRules):

        transRot = ["Translate", "Rotate"]
        modes = ["x", "y", "z"]
        value = 1

        if isCenterCurve:
            objType = "Center"
        else:
            objType = "Mirror"

        for loopRule in invertRules:
            for loopMode in modes:
                for loopTransRot in transRot:
                    rule = "%sObjs%s%s" % (objType, loopTransRot,
                                           loopMode.title())

                    if loopRule == rule:
                        if eval("animMod.isNode%s('%s', '%s')" %
                                (loopTransRot, aCurve, loopMode)):
                            value = -1

        return value

    def unselectMirrorObjs(self, side):
        objects = animMod.getObjsSel()

        if side == "center":
            objs = animMod.getMirrorObjs(objects, side="left")
            objects.extend(objs)
            objs.extend(animMod.getMirrorObjs(objects, side="right"))
            objects.extend(objs)
            objs.extend(animMod.getMirrorObjs(objects, side="left"))

            centerObjs = [
                loopObj for loopObj in objects
                if loopObj not in objs and loopObj and cmds.objExists(loopObj)
            ]

            if len(centerObjs) > 0: cmds.select(centerObjs, deselect=True)
        else:
            if side == "left": side = "right"
            elif side == "right": side = "left"
            objs = animMod.getMirrorObjs(objects, side=side)
            objs = [
                loopObj for loopObj in objs
                if loopObj and cmds.objExists(loopObj)
            ]

            if len(objs) > 0: cmds.select(objs, deselect=True)

    def selectMirrorObjs(self, add, lastObj=None):
        objects = animMod.getObjsSel()
        mirrorObjs = animMod.getMirrorObjs(objects)
        sel = []

        if mirrorObjs:
            for n, loopObj in enumerate(mirrorObjs):
                if loopObj:
                    if cmds.objExists(loopObj): sel.append(loopObj)
                else:
                    #central controller
                    sel.append(objects[n])

        if len(sel) > 0:

            if lastObj:
                cmds.select(sel, addFirst=add)
            else:
                cmds.select(sel, add=add)

    def applyMirror(self, pasteAndCycle=False):

        cmds.waitCursor(state=True)

        range = animMod.getTimelineRange()
        range[1] = int(range[1])
        total = range[1] - range[0]

        getCurves = animMod.getAnimCurves()
        animCurves = getCurves[0]
        getFrom = getCurves[1]

        invertRules = self.getInvertRules()

        if animCurves:
            status = "aTools - Applying mirror..."
            utilMod.startProgressBar(status)
            totalSteps = len(animCurves)
            firstStep = 0
            thisStep = 0
            estimatedTime = None
            startChrono = None

            mirrorCurves = animMod.getMirrorObjs(animCurves)
            keyValues = animMod.getTarget("keyValues", animCurves, getFrom)
            keyTimes = animMod.getTarget("keyTimes", animCurves, getFrom)
            currValues = animMod.getTarget("currValues", animCurves, getFrom)
            keysIndexSel = animMod.getTarget("keysIndexSel", animCurves,
                                             getFrom)
            keyTangentsAngle = animMod.getTarget("keyTangentsAngle",
                                                 animCurves, getFrom)
            keyTangentsType = animMod.getTarget("keyTangentsType", animCurves,
                                                getFrom)
            currTime = cmds.currentTime(query=True)

            if keysIndexSel:

                #create dummy key
                #objects     = animMod.getObjsSel()
                #mirrorObjs  = animMod.getMirrorObjs(objects)
                #animMod.createDummyKey(mirrorObjs)

                for thisStep, aCurve in enumerate(animCurves):

                    startChrono = utilMod.chronoStart(startChrono, firstStep,
                                                      thisStep, totalSteps,
                                                      estimatedTime, status)

                    mCurve = mirrorCurves[thisStep]
                    isCenterCurve = (mCurve == None)
                    mirrorInvertValue = self.mirrorInvert(
                        aCurve, isCenterCurve, invertRules)
                    if mCurve and cmds.objExists(mCurve):
                        tCurve = mCurve
                    else:
                        tCurve = aCurve

                    if not cmds.objExists(tCurve): continue

                    animMod.createDummyKey([tCurve])

                    if len(keysIndexSel[thisStep]) > 0:
                        #delete keys
                        cmds.cutKey(
                            tCurve,
                            time=(
                                keyTimes[thisStep][keysIndexSel[thisStep][0]],
                                keyTimes[thisStep][keysIndexSel[thisStep][-1]]
                            ),
                            clear=True)

                        for key in keysIndexSel[thisStep]:
                            keyValue = keyValues[thisStep][
                                key] * mirrorInvertValue
                            inTangAngleValue = keyTangentsAngle[thisStep][key][
                                0] * mirrorInvertValue
                            outTangAngleValue = keyTangentsAngle[thisStep][
                                key][1] * mirrorInvertValue

                            #apply keys
                            if pasteAndCycle:
                                t = keyTimes[thisStep][key] + (total / 2.)

                                if t == range[1]:
                                    #repeat key at first frame
                                    t1 = t - total
                                    time = (t1, t1)
                                    cmds.setKeyframe(tCurve,
                                                     time=time,
                                                     value=keyValue)
                                    cmds.keyTangent(tCurve,
                                                    time=time,
                                                    inAngle=inTangAngleValue,
                                                    outAngle=outTangAngleValue)
                                    cmds.keyTangent(
                                        tCurve,
                                        time=time,
                                        inTangentType=keyTangentsType[thisStep]
                                        [key][0],
                                        outTangentType=keyTangentsType[
                                            thisStep][key][1])

                                elif t > range[1]:
                                    #fist half
                                    t -= total

                                time = (t, t)

                            else:
                                time = (keyTimes[thisStep][key],
                                        keyTimes[thisStep][key])

                            cmds.setKeyframe(tCurve, time=time, value=keyValue)
                            cmds.keyTangent(tCurve,
                                            time=time,
                                            inAngle=inTangAngleValue,
                                            outAngle=outTangAngleValue)
                            cmds.keyTangent(
                                tCurve,
                                time=time,
                                inTangentType=keyTangentsType[thisStep][key]
                                [0],
                                outTangentType=keyTangentsType[thisStep][key]
                                [1])
                    else:  #no keys#invert translate x
                        keyValue = currValues[thisStep] * mirrorInvertValue

                        #apply keys
                        cmds.setKeyframe(tCurve,
                                         time=(currTime, currTime),
                                         value=keyValue)

                    animMod.deleteDummyKey([tCurve])

                    estimatedTime = utilMod.chronoEnd(startChrono, firstStep,
                                                      thisStep, totalSteps)

                #delete dummy key
                #animMod.deleteDummyKey(mirrorObjs)

            self.selectMirrorObjs(False)
            utilMod.setProgressBar(endProgress=True)

        animMod.refresh()
        cmds.waitCursor(state=False)
Beispiel #15
0
    def clearScriptJobs(self):

        utilMod.killScriptJobs("G.selectSetsScriptJobs")
Beispiel #16
0
 def switch(self, onOff):
     
     utilMod.killScriptJobs("G.autoSmartSnapKeysJobs")
             
     if onOff:
         G.autoSmartSnapKeysJobs.append(cmds.scriptJob(runOnce = False, killWithScene = False, event =('timeChanged', self.smartSnapKeys )))
Beispiel #17
0
 def __init__(self):        
     utilMod.killScriptJobs("G.autoSmartSnapKeysJobs")               
Beispiel #18
0
class TransformAll(object):    
    
    utilMod.killScriptJobs("G.transformAllScriptJobs")
        
    def __init__(self):
        
        G.deferredManager.removeFromQueue("transformAll")  
        G.deferredManager.removeFromQueue("TA_blinking")  
        
        if G.aToolsBar.transformAll: return
        G.aToolsBar.transformAll = self
        
        self.currentValues      = {}
        self.allValues          = {}
        self.range              = None
        self.onOff              = False
        self.blendRangeMode     = False
        self.blendImg           = ""
        G.TA_messages           = G.TA_messages or {"anim":[], "node":[], "scene":[]}
        
        self.killJobs()
        
    def blinkingButton(self, onOff):
        
        if onOff:   G.aToolsBar.timeoutInterval.setInterval(self.toggleButtonActive, .3, id="TA_blinking")
        else:       G.aToolsBar.timeoutInterval.stopInterval("TA_blinking")
        

    def toggleButtonActive(self):
        onOff = "active" in cmds.iconTextButton("transformAllBtn", query=True, image=True)

        self.setButtonImg(not onOff)

    def popupMenu(self, *args):    
        
        cmds.popupMenu              ()
        cmds.menuItem               ("blendRangeModeMenu", label="Blend Range Mode", checkBox=self.blendRangeMode, command=self.setBlendRangeMode)
        
    def setBlendRangeMode(self, *args):
        self.blendRangeMode = args[0]
        if self.blendRangeMode: self.blendImg       = "_blend"
        else:                   self.blendImg       = ""
        
        self.setButtonImg(self.onOff)
        self.warn()
        
    def setButtonImg(self, onOff):
        if onOff:
            cmds.iconTextButton("transformAllBtn", edit=True, image=uiMod.getImagePath("specialTools_transform_all%s_active"%self.blendImg), highlightImage= uiMod.getImagePath("specialTools_transform_all%s_active"%self.blendImg))
        else:
            cmds.iconTextButton("transformAllBtn", edit=True, image=uiMod.getImagePath("specialTools_transform_all%s"%self.blendImg), highlightImage= uiMod.getImagePath("specialTools_transform_all%s copy"%self.blendImg))
        

    def switch(self):
        
        mod         = uiMod.getModKeyPressed()
            
        if mod == "ctrl":
            self.setBlendRangeMode(not self.blendRangeMode)
            if self.onOff: self.onOff = False
                
        
        self.onOff  = (not self.onOff)
        self.setButtonImg(self.onOff) 
        self.blinkingButton(self.onOff)  
              
        self.setMode(self.onOff)
    
    def killJobs(self):
        G.deferredManager.removeFromQueue("transformAll")  
        self.animCurvesToSend   = []
        self.removeMessages() 
        utilMod.killScriptJobs("G.transformAllScriptJobs") 
        
    
    def setMode(self, onOff):
        
        self.killJobs()
                      
        if onOff: 
            
            #self.allAnimCurves = utilMod.getAllAnimCurves()   
            self.allValues = {}
            self.setRange()                  
            self.updateCurrentValues()
            utilMod.deselectTimelineRange()
            
            G.transformAllScriptJobs.append(cmds.scriptJob(runOnce = False, killWithScene = False, event =('timeChanged', self.updateCurrentValues )))
            G.transformAllScriptJobs.append(cmds.scriptJob(runOnce = False, killWithScene = False, event =('SelectionChanged', self.updateCurrentValues )))
            
            self.warn()
            
    
        else:
            cmds.warning("Transform All is OFF.")  
    
    def addAnimMessages(self):
        
        self.removeMessages()        
        G.TA_messages["anim"].append(OpenMayaAnim.MAnimMessage.addAnimCurveEditedCallback(self.sendToSetValues))
 
        
    def removeMessages(self):  
        
        try:
            for loopId in G.TA_messages["anim"]:
                OpenMayaAnim.MAnimMessage.removeCallback(loopId)
        except: pass   
        
        G.TA_messages["anim"]  = []    

    
    

    
    def sendToSetValues(self, *args):  
        
        curveMsg                = args[0]
        animCurves              = [OpenMaya.MFnDependencyNode(curveMsg[n]).name() for n in xrange(curveMsg.length())] 
        
        if OpenMaya.MGlobal.isUndoing() or OpenMaya.MGlobal.isRedoing(): 
            self.updateCurrentValues(animCurves)
            return
          
        self.animCurvesToSend.extend(animCurves)
        
        
        animCurves          = list(set(self.animCurvesToSend))    
        
        G.deferredManager.removeFromQueue("transformAll")
        function            = lambda *args:self.setValues(animCurves)
        G.deferredManager.sendToQueue(function, 1, "transformAll")
        
    
    def getRange(self):
        
        animCurves  = cmds.keyframe(query=True, name=True, selected=True)
        
        if animCurves:
        
            keysSel     = animMod.getTarget("keysSel", animCurves, "graphEditor")
            keysSel     = utilMod.mergeLists(keysSel)   
            range       = [min(keysSel), max(keysSel)]
                
        else:
            G.playBackSliderPython  = G.playBackSliderPython or mel.eval('$aTools_playBackSliderPython=$gPlayBackSlider')
            range                   = cmds.timeControl(G.playBackSliderPython, query=True, rangeArray=True)
            
            range[1] -= 1
                
        return range    
     
    def getCurrentValues(self, animCurves):
         if animCurves:  
            result  = {"keyValues":[], "timeValues":[]}    
            for loopCurve in animCurves:
                time = cmds.keyframe(loopCurve, selected=True, query=True, timeChange=True)
                
                if time:
                    time = [time[0], time[-1]]
                    result["keyValues"].append(cmds.keyframe(loopCurve, query=True, time=(time[0],time[-1]), valueChange=True))
                else:
                    time = cmds.currentTime(query=True); time = [time, time]
                    result["keyValues"].append(cmds.keyframe(loopCurve, query=True, eval=True, valueChange=True))
                
                result["timeValues"].append(time)
                
            return result 
    
     
    def updateCurrentValues(self, animCurves=None, *args):      
 
        cmds.undoInfo(stateWithoutFlush=False)
   
        self.removeMessages() 
 
        if not animCurves: animCurves = utilMod.getAllAnimCurves(selection=True)
        if not animCurves: return 
         
        for loopCurve in animCurves:
            #if loopCurve in self.allAnimCurves:            
            self.currentValues[loopCurve]   = self.getCurrentValues([loopCurve])["keyValues"][0]
            self.allValues[loopCurve]       = animMod.getTarget("keyValues", [loopCurve])[0]
            
        
        self.addAnimMessages()
        cmds.undoInfo(stateWithoutFlush=True)
        

    
    def setValues(self, animCurves):
        
        cmds.refresh(suspend=True)
        
        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.removeMessages() 
        self.warn()
        
        values                  = self.getCurrentValues(animCurves)
        newKeyValues            = values["keyValues"]
        timeValues              = values["timeValues"]
        offsetValues            = []
        offsetPercentsA         = []
        offsetPercentsB         = []
        pivotAs                 = []
        pivotBs                 = []
        self.animCurvesToSend   = []  
        
       
        for n, loopCurve in enumerate(animCurves):
            
            oldVal      = self.currentValues[loopCurve][0]
            newVal      = newKeyValues[n][0]
                       
            if self.blendRangeMode:          
                        
                pivotA          = cmds.keyframe(loopCurve, query=True, eval=True, time=(self.range[0],self.range[0]), valueChange=True)[0]
                pivotB          = cmds.keyframe(loopCurve, query=True, eval=True, time=(self.range[1],self.range[1]), valueChange=True)[0]
                
               
                if oldVal == pivotA: 
                    pivotA          = newVal
                    offsetPercentA  = 0
                else:
                    offsetPercentA  = float((newVal-pivotA)/(oldVal-pivotA))
                if oldVal == pivotB: 
                    pivotB          = newVal
                    offsetPercentB  = 0
                else:
                    offsetPercentB  = float((newVal-pivotB)/(oldVal-pivotB))
  
                offsetPercentsA.append(offsetPercentA)
                offsetPercentsB.append(offsetPercentB)  
                pivotAs.append(pivotA)
                pivotBs.append(pivotB)
                
            else:
                offsetVal   = newVal - oldVal
                
                offsetValues.append(offsetVal)  
        
            
        #reset change        
        cmds.undoInfo(stateWithoutFlush=False)
        for loopCurve in self.allValues.keys():  
            if loopCurve in animCurves:          
                valueChange = self.allValues[loopCurve]
                for n, loopValue in enumerate(valueChange):
                    cmds.keyframe(loopCurve, edit=True, index=(n,n), valueChange=loopValue)
                #self.allValues[] = {}
        cmds.undoInfo(stateWithoutFlush=True)
        
        
        
        #set values for all keys  
        curvesToUpdate = []      
        
        if self.blendRangeMode:  
            for n, loopCurve in enumerate(animCurves):
                time        = timeValues[n]
                timeOffsetA = .01
                timeOffsetB = .01
                
                if time[0] == self.range[0]: timeOffsetA = 0
                if time[1] == self.range[1]: timeOffsetB = 0
                
                if timeOffsetA != 0 and timeOffsetB != 0 and not self.range[0] < time[0] <= time[1] < self.range[1]: 
                    cmds.warning("Selected keys out of range %s"%self.range)
                    continue 
                
                offsetPercentA = offsetPercentsA[n]
                offsetPercentB = offsetPercentsB[n]
                #if offsetPercentA != 0 or offsetPercentB != 0:
                pivotA = pivotAs[n]
                pivotB = pivotBs[n]                    
                curvesToUpdate.append(loopCurve)
                cmds.scaleKey(loopCurve, time=(self.range[0]+timeOffsetA, time[1]), valuePivot=pivotA, valueScale=offsetPercentA)
                cmds.scaleKey(loopCurve, time=(time[1]+.01, self.range[1]-timeOffsetB), valuePivot=pivotB, valueScale=offsetPercentB) 
                    
        else:
            for n, loopCurve in enumerate(animCurves):
                if offsetValues[n] != 0:
                    curvesToUpdate.append(loopCurve)
                    if self.range == "All Keys":
                        #pass
                        cmds.keyframe(loopCurve, edit=True, valueChange=offsetValues[n], relative=True)
                    else:
                        cmds.keyframe(loopCurve, edit=True, time=(self.range[0], self.range[1]), valueChange=offsetValues[n], relative=True)
        
        
        self.updateCurrentValues(curvesToUpdate)      
        cmds.undoInfo(closeChunk=True)
        cmds.refresh(suspend=False)        
        
        
    def warn(self): 
        if self.blendRangeMode: 
            blendTxt = "Blend Range Mode "
        else:
            blendTxt = ""
                    
        cmds.warning("Transform All %sis ON. Please remember to turn it OFF when you are done. Acting on range: %s"%(blendTxt, self.range))  
        
    def setRange(self):
        self.range = self.getRange()
        
        if self.range[1] - self.range[0] <= 1: #if only one key selected     
            if self.blendRangeMode: self.range = [cmds.playbackOptions(query=True, minTime=True), cmds.playbackOptions(query=True, maxTime=True)] 
            else:                   self.range = "All Keys"
Beispiel #19
0
    def clearScriptJobs(self):

        utilMod.killScriptJobs("G.selectSetsScriptJobs")
Beispiel #20
0
class MicroTransform(object):

    utilMod.killScriptJobs("G.microTransformScriptJobs")

    def __init__(self):

        G.deferredManager.removeFromQueue("MT_blinking")

        if G.aToolsBar.microTransform: return
        G.aToolsBar.microTransform = self

        self.attributes = [
            'translate', 'translateX', 'translateY', 'translateZ', 'rotate',
            'rotateX', 'rotateY', 'rotateZ', 'scale', 'scaleX', 'scaleY',
            'scaleZ'
        ]

        self.multiplierValues = [{
            "name": "ultraSlow",
            "value": .05
        }, {
            "name": "superSlow",
            "value": .2
        }, {
            "name": "slow",
            "value": .5
        }, {
            "name": "medium",
            "value": 1
        }]
        self.defaultMultiplier = "slow"
        self.microTransformStartTimer = {}
        self.microTransformValues = {}
        self.onOff = False
        self.rotationOrientMode = cmds.manipRotateContext('Rotate',
                                                          query=True,
                                                          mode=True)

        self.setMultiplier(self.getMultiplier())
        self.removeMicroTransform()
        self.blinkingButton(self.onOff)

    def blinkingButton(self, onOff):

        if onOff:
            G.aToolsBar.timeoutInterval.setInterval(self.toggleButtonActive,
                                                    .3,
                                                    id="MT_blinking")
        else:
            G.aToolsBar.timeoutInterval.stopInterval("MT_blinking")

    def toggleButtonActive(self):
        onOff = "active" in cmds.iconTextButton("microTransformBtn",
                                                query=True,
                                                image=True)

        self.setButtonImg(not onOff)

    def setButtonImg(self, onOff):
        if onOff:
            cmds.iconTextButton("microTransformBtn",
                                edit=True,
                                image=uiMod.getImagePath(
                                    "specialTools_micro_transform_active"),
                                highlightImage=uiMod.getImagePath(
                                    "specialTools_micro_transform_active"))
        else:
            cmds.iconTextButton(
                "microTransformBtn",
                edit=True,
                image=uiMod.getImagePath("specialTools_micro_transform"),
                highlightImage=uiMod.getImagePath(
                    "specialTools_micro_transform copy"))

    def switch(self):

        self.onOff = (not self.onOff)
        self.setButtonImg(self.onOff)
        self.blinkingButton(self.onOff)
        self.setMode(self.onOff)

    def setMode(self, onOff):

        utilMod.killScriptJobs("G.microTransformScriptJobs")

        if onOff:

            self.rotationOrientMode = cmds.manipRotateContext('Rotate',
                                                              query=True,
                                                              mode=True)
            cmds.manipRotateContext('Rotate', edit=True, mode=2)  #gimbal
            #update values on turning on
            self.addMicroTransform()

            G.microTransformScriptJobs = []
            # get the current selected object values
            G.microTransformScriptJobs.append(
                cmds.scriptJob(runOnce=False,
                               killWithScene=False,
                               event=('SelectionChanged',
                                      self.addMicroTransform)))
            G.microTransformScriptJobs.append(
                cmds.scriptJob(runOnce=False,
                               killWithScene=False,
                               event=('timeChanged', self.updateValues)))
            G.microTransformScriptJobs.append(
                cmds.scriptJob(runOnce=False,
                               killWithScene=False,
                               event=('Undo', self.updateValues)))
            G.microTransformScriptJobs.append(
                cmds.scriptJob(runOnce=False,
                               killWithScene=False,
                               event=('Redo', self.updateValues)))
            G.microTransformScriptJobs.append(
                cmds.scriptJob(runOnce=False,
                               killWithScene=False,
                               event=('DragRelease', self.release)))

            #print "microTransform is ON."

        else:
            cmds.manipRotateContext('Rotate',
                                    edit=True,
                                    mode=self.rotationOrientMode)
            self.removeMicroTransform()
            #print "microTransform is OFF."

    def changedMicroTransform(self, msg, mplug, otherMplug, clientData):

        #cmds.undoInfo(stateWithoutFlush=False)

        if om.MNodeMessage.kAttributeSet == (
                om.MNodeMessage.kAttributeSet & msg
        ) and not om.MGlobal.isUndoing() and not om.MGlobal.isRedoing():
            nodeName, attrName = mplug.name().split('.')

            #print "changed!"

            if attrName not in self.attributes: return

            nodeAttr = mplug.name()
            val = cmds.getAttr(nodeAttr)
            mtValue = self.microTransformValues["%s_%s" % (nodeName, attrName)]

            if str(val) != str(mtValue):
                #timer
                if not self.microTransformStartTimer.has_key("%s" % nodeName):
                    self.microTransformStartTimer["%s" %
                                                  nodeName] = cmds.timerX()
                microTransformTimer = cmds.timerX(
                    startTime=self.microTransformStartTimer["%s" % nodeName])
                self.microTransformStartTimer["%s" % nodeName] = cmds.timerX()

                microTransformTimer *= 50
                if microTransformTimer == 0: microTransformTimer = 1000
                mult = self.multiplier / microTransformTimer

                if mult >= self.multiplier: mult = self.multiplier

                self.undoChunkFn("open")
                #print "changedMicroTransform"

                if type(val) is list:

                    temp = ()
                    for n, loopVal in enumerate(val[0]):
                        dif = loopVal - mtValue[0][n]
                        temp = temp + (mtValue[0][n] + (dif * mult), )
                    newVal = [temp]

                    self.microTransformValues["%s_%s" %
                                              (nodeName, attrName)] = newVal
                    #xyz
                    self.microTransformValues["%s_%sX" %
                                              (nodeName,
                                               attrName)] = newVal[0][0]
                    self.microTransformValues["%s_%sY" %
                                              (nodeName,
                                               attrName)] = newVal[0][1]
                    self.microTransformValues["%s_%sZ" %
                                              (nodeName,
                                               attrName)] = newVal[0][2]

                    eval("cmds.setAttr(nodeAttr, %s,%s,%s)" %
                         (newVal[0][0], newVal[0][1], newVal[0][2]))
                    #xyz
                    cmds.setAttr("%sX" % nodeAttr, newVal[0][0])
                    cmds.setAttr("%sY" % nodeAttr, newVal[0][1])
                    cmds.setAttr("%sZ" % nodeAttr, newVal[0][2])

                else:
                    dif = val - mtValue
                    newVal = mtValue + (dif * mult)
                    self.microTransformValues["%s_%s" %
                                              (nodeName, attrName)] = newVal

                    #xyz inverse
                    val = cmds.getAttr("%s.%s" % (nodeName, attrName[:-1]))
                    self.microTransformValues["%s_%s" %
                                              (nodeName, attrName[:-1])] = val

                    cmds.setAttr(nodeAttr, newVal)

            else:
                self.microTransformValues["%s_%s" %
                                          (nodeName,
                                           attrName)] = cmds.getAttr(nodeAttr)
                if type(val) is list:
                    valX = cmds.getAttr("%s.%sX" % (nodeName, attrName))
                    valY = cmds.getAttr("%s.%sY" % (nodeName, attrName))
                    valZ = cmds.getAttr("%s.%sZ" % (nodeName, attrName))
                    #xyz
                    self.microTransformValues["%s_%sX" %
                                              (nodeName, attrName)] = valX
                    self.microTransformValues["%s_%sY" %
                                              (nodeName, attrName)] = valY
                    self.microTransformValues["%s_%sZ" %
                                              (nodeName, attrName)] = valZ

                else:
                    #xyz inverse
                    val = cmds.getAttr("%s.%s" % (nodeName, attrName[:-1]))
                    self.microTransformValues["%s_%s" %
                                              (nodeName, attrName[:-1])] = val

        #cmds.undoInfo(stateWithoutFlush=True)

    def release(self):

        self.undoChunkFn("close")
        self.updateValues()
        self.microTransformStartTimer = {}

    def undoChunkFn(self, openClose):
        if openClose == "open":
            if self.undoChunk == "closed":
                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.undoChunk = "open"
                #print "openChunk"
        else:
            if self.undoChunk == "open":
                cmds.undoInfo(closeChunk=True)
                self.undoChunk = "closed"
                #print "closeChunk"

    def addMicroTransform(self):

        self.updateValues()
        cmds.undoInfo(stateWithoutFlush=False)

        sel = cmds.ls(selection=True)

        if G.MT_lastSel:
            graphEditorFocus = cmds.getPanel(withFocus=True) == "graphEditor1"
            if sel == G.MT_lastSel and graphEditorFocus:
                cmds.undoInfo(stateWithoutFlush=True)
                return

        G.MT_lastSel = sel

        if len(sel) <= 0:
            cmds.undoInfo(stateWithoutFlush=True)
            return

        self.removeMicroTransform()
        G.microTransformIds = []
        self.undoChunk = "closed"
        MSelectionList = om.MSelectionList()
        om.MGlobal.getActiveSelectionList(MSelectionList)
        node = om.MObject()

        for n, loopSel in enumerate(sel):

            MSelectionList.getDependNode(n, node)
            clientData = None
            G.microTransformIds.append(
                om.MNodeMessage.addAttributeChangedCallback(
                    node, self.changedMicroTransform, clientData))

        cmds.undoInfo(stateWithoutFlush=True)

    def removeMicroTransform(self):

        try:
            for loopId in G.microTransformIds:
                om.MNodeMessage.removeCallback(loopId)
        except:
            pass

        G.microTransformIds = None

    def updateValues(self):
        #print "updateValues"

        self.microTransformValues = {}
        sel = cmds.ls(selection=True)

        for loopSel in sel:
            for loopAttr in self.attributes:
                val = cmds.getAttr("%s.%s" % (loopSel, loopAttr))
                self.microTransformValues["%s_%s" % (loopSel, loopAttr)] = val

    def setMultiplier(self, option):
        name = None
        for loopOption in self.multiplierValues:
            if loopOption["name"] == option:
                value = loopOption["value"]
                name = loopOption["name"]

        if not name:  #in case file is corrupt
            self.setMultiplier(self.defaultMultiplier)
            return

        self.multiplier = value
        aToolsMod.saveInfoWithUser("userPrefs", "microTransform", name)

    def getMultiplier(self):
        name = aToolsMod.loadInfoWithUser("userPrefs", "microTransform")
        if name == None: name = self.defaultMultiplier

        return name

    def popupMenu(self, *args):
        menu = cmds.popupMenu()
        cmds.popupMenu(menu,
                       edit=True,
                       postMenuCommand=self.populateMenu,
                       postMenuCommandOnce=True)

    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)
Beispiel #21
0
 def killJobs(self):
     G.deferredManager.removeFromQueue("transformAll")  
     self.animCurvesToSend   = []
     self.removeMessages() 
     utilMod.killScriptJobs("G.transformAllScriptJobs") 
Beispiel #22
0
 def __init__(self):        
     utilMod.killScriptJobs("G.autoSmartSnapKeysJobs")               
Beispiel #23
0
 def killJobs(self):
     G.deferredManager.removeFromQueue("transformAll")
     self.animCurvesToSend = []
     self.removeMessages()
     utilMod.killScriptJobs("G.transformAllScriptJobs")