Ejemplo n.º 1
2
def setSmartKey(time=None, animCurves=None, select=True, insert=True, replace=True, addTo=False):
    
    if not time: time   = animMod.getTimelineTime()    
    getFrom             = "timeline"
    
    if not animCurves:
        getCurves  = animMod.getAnimCurves()
        animCurves = getCurves[0]
        getFrom    = getCurves[1]
    
    
    if animCurves and getFrom != "timeline": 
        cmds.setKeyframe(animCurves, time=time, insert=insert)
        if select: cmds.selectKey(animCurves, replace=replace, addTo=addTo, time=time)
        
    else:
        objects = animMod.getObjsSel()
        if objects:
            
            channelboxSelObjs = animMod.channelBoxSel()
            if channelboxSelObjs:
                #objsAttrs     = ["%s.%s"%(loopObj, loopChannelboxSel) for loopObj in objects for loopChannelboxSel in channelboxSel]
                         
                #key selected attributes in the channelbox
                for n, loopObjAttr in enumerate(channelboxSelObjs):
                    prevKey       = cmds.findKeyframe(loopObjAttr, time=(time,time), which="previous")
                    tangentType   = cmds.keyTangent(loopObjAttr, query=True, outTangentType=True, time=(prevKey,prevKey)) 
               
                    if not tangentType: #if there is no key 
                        tangentType = cmds.keyTangent(query=True, g=True, outTangentType=True)
                        inTangentType  = tangentType[0].replace("fixed", "auto").replace("step", "auto")
                        outTangentType = tangentType[0].replace("fixed", "auto")
                        cmds.setKeyframe(loopObjAttr, time=time, insert=False, shape=False, inTangentType=inTangentType, outTangentType=outTangentType)
                        continue
                    
                    inTangentType  = tangentType[0].replace("fixed", "auto").replace("step", "auto")
                    outTangentType = tangentType[0].replace("fixed", "auto")
                
                    cmds.setKeyframe(loopObjAttr, time=time, insert=insert, shape=False, inTangentType=inTangentType, outTangentType=outTangentType)
                    
            else:
                #allChannels   = animMod.getAllChannels(objects)
                #objAttrs      = ["%s.%s"%(objects[n], loopAttr) for n, loopObj in enumerate(allChannels) for loopAttr in loopObj]
                prevKeys      = [cmds.findKeyframe(obj, time=(time,time), which="previous") for obj in objects]
                tangentTypes  = [cmds.keyTangent(obj, query=True, outTangentType=True, time=(prevKeys[n],prevKeys[n])) for n, obj in enumerate(objects)]
                #prevKeys      = [cmds.findKeyframe(obj, time=(time,time), which="previous") for obj in objAttrs]
                #tangentTypes  = [cmds.keyTangent(obj, query=True, outTangentType=True, time=(prevKeys[n],prevKeys[n])) for n, obj in enumerate(objAttrs)]
                #key all atributes
                cmds.setKeyframe(objects, time=time, insert=insert, shape=False) 
                #cmds.setKeyframe(objAttrs, time=time, insert=insert, shape=False)    
                            
                if insert: #will force create key if there is no key
                    for n, loopTangent in enumerate(tangentTypes):
                        if not loopTangent:
                            cmds.setKeyframe(objects[n], time=time, insert=False, shape=False)
Ejemplo n.º 2
0
    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))
Ejemplo n.º 3
0
def setSmartKey(time=None,
                animCurves=None,
                select=True,
                insert=True,
                replace=True,
                addTo=False):

    if not time: time = animMod.getTimelineTime()
    getFrom = "timeline"

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

    if animCurves and getFrom != "timeline":
        cmds.setKeyframe(animCurves, time=time, insert=insert)
        if select:
            cmds.selectKey(animCurves, replace=replace, addTo=addTo, time=time)

    else:
        objects = animMod.getObjsSel()
        if objects:

            channelboxSelObjs = animMod.channelBoxSel()
            if channelboxSelObjs:
                #objsAttrs     = ["%s.%s"%(loopObj, loopChannelboxSel) for loopObj in objects for loopChannelboxSel in channelboxSel]

                #key selected attributes in the channelbox
                for n, loopObjAttr in enumerate(channelboxSelObjs):
                    prevKey = cmds.findKeyframe(loopObjAttr,
                                                time=(time, time),
                                                which="previous")
                    tangentType = cmds.keyTangent(loopObjAttr,
                                                  query=True,
                                                  outTangentType=True,
                                                  time=(prevKey, prevKey))

                    if not tangentType:  #if there is no key
                        tangentType = cmds.keyTangent(query=True,
                                                      g=True,
                                                      outTangentType=True)
                        inTangentType = tangentType[0].replace(
                            "fixed", "auto").replace("step", "auto")
                        outTangentType = tangentType[0].replace(
                            "fixed", "auto")
                        cmds.setKeyframe(loopObjAttr,
                                         time=time,
                                         insert=False,
                                         shape=False,
                                         inTangentType=inTangentType,
                                         outTangentType=outTangentType)
                        continue

                    inTangentType = tangentType[0].replace("fixed",
                                                           "auto").replace(
                                                               "step", "auto")
                    outTangentType = tangentType[0].replace("fixed", "auto")

                    cmds.setKeyframe(loopObjAttr,
                                     time=time,
                                     insert=insert,
                                     shape=False,
                                     inTangentType=inTangentType,
                                     outTangentType=outTangentType)

            else:
                #allChannels   = animMod.getAllChannels(objects)
                #objAttrs      = ["%s.%s"%(objects[n], loopAttr) for n, loopObj in enumerate(allChannels) for loopAttr in loopObj]
                prevKeys = [
                    cmds.findKeyframe(obj, time=(time, time), which="previous")
                    for obj in objects
                ]
                tangentTypes = [
                    cmds.keyTangent(obj,
                                    query=True,
                                    outTangentType=True,
                                    time=(prevKeys[n], prevKeys[n]))
                    for n, obj in enumerate(objects)
                ]
                #prevKeys      = [cmds.findKeyframe(obj, time=(time,time), which="previous") for obj in objAttrs]
                #tangentTypes  = [cmds.keyTangent(obj, query=True, outTangentType=True, time=(prevKeys[n],prevKeys[n])) for n, obj in enumerate(objAttrs)]
                #key all atributes
                cmds.setKeyframe(objects,
                                 time=time,
                                 insert=insert,
                                 shape=False)
                #cmds.setKeyframe(objAttrs, time=time, insert=insert, shape=False)

                if insert:  #will force create key if there is no key
                    for n, loopTangent in enumerate(tangentTypes):
                        if not loopTangent:
                            cmds.setKeyframe(objects[n],
                                             time=time,
                                             insert=False,
                                             shape=False)