Exemplo n.º 1
0
def jpmSavePoseToFile_OLD(name, selected=[], keyableAttrs=[], refReTarget=0):
    ##initialize some variables
    verboseLevel = 0
    cancel = 0
    safeFileCommand = ""
    reCreateKeyableAttrs = 1

    ##sanity check to see if anything is selected
    numOfObjs = len(selected)
    if numOfObjs <= 0:
        mm.error(
            "Nothing is currently selected. No file created or action taken.")

    ##begin looping through objects
    safeFileDict = {}
    for object in selected:
        prefix = ref.jpmAmIaReference(object)
        if refReTarget:
            strippedObj = jpmDeConstObj(object, prefix)
        else:
            strippedObj = object
        safeFileCommand = (safeFileCommand + "ob::" + strippedObj + "\n")
        if keyableAttrs[0] == "" or reCreateKeyableAttrs == 1:
            keyableAttrs = cmds.listAttr(object,
                                         r=1,
                                         w=1,
                                         k=1,
                                         u=1,
                                         v=1,
                                         m=1,
                                         s=1)
            reCreateKeyableAttrs = 1
        ##begin looping through attributes
        for attr in keyableAttrs:
            safeFileCommand = (safeFileCommand + "at::" + attr + "\n")
            staticValue = cmds.getAttr(object + "." + attr)
            safeFileCommand = (safeFileCommand + "sv::" + str(staticValue) +
                               "\n")

    safeFileDict["AWFileType"] = "sel"

    ##actually write the file out
    saveFile = file(name, "w+")
    saveFile.write(safeFileCommand)
    saveFile.close()
Exemplo n.º 2
0
def jpmSaveSelectionToFile(name, selected=[], refReTarget=0):
    ##initialize some variables
    verboseLevel = 0
    cancel = 0
    safeFileCommand = ""

    ##sanity check to see if anything is selected
    #	numOfObjs = len(selected)
    #if numOfObjs <= 0:
    #	mm.error( "Nothing is currently selected. No file created or action taken." )

    ##begin looping through objects
    for object in selected:
        prefix = ref.jpmAmIaReference(object)
        if refReTarget:
            strippedObj = jpmDeConstObj(object, prefix)
        else:
            strippedObj = object
        safeFileCommand = (safeFileCommand + "sl::" + strippedObj + "\n")

    ##actually write the file out
    saveFile = file(name, "w+")
    saveFile.write(safeFileCommand)
    saveFile.close()
Exemplo n.º 3
0
def jpmRestoreFromFile(filename, placeTime, placeValue, selectionType,
                       refReTarget):
    ##get the data from the file
    linesFromFile = jpReadLines(filename)

    ##initialize some variables
    currentObject = ""
    currentAttr = ""
    selectionAdd = 0
    selectionToggle = 0
    if refReTarget:
        prefix = ref.jpmAmIaReference(cmds.ls(sl=1)[0])
        if prefix == "0":
            prefix = ""
    else:
        prefix = ""

    ##initialize the progress bars
    progress = 0
    curLine = 0
    gMainProgressBar = mm.eval('$tmp = $gMainProgressBar')
    cmds.progressWindow(t="Reading Curves",
                        pr=progress,
                        st="Reading: ",
                        min=0,
                        max=100)
    cmds.progressBar(gMainProgressBar,
                     edit=1,
                     bp=1,
                     st="Reading: ",
                     min=0,
                     max=100)

    ##based on selectionType change some variables
    if selectionType == "add":
        selectionAdd = 1
    if selectionType == "toggle":
        selectionToggle = 1
    if selectionType == "replace":
        cmds.select(cl=1)
        selectionAdd = 1
    if selectionType == "subtract":
        currentSel = cmds.ls(sl=1)

    ##begin looping through lines from the file
    for line in linesFromFile:
        ##progress the progress bars
        progress = ((float(curLine) / float(len(linesFromFile))) * 100)
        cmds.progressWindow(edit=1,
                            ii=1,
                            pr=progress,
                            st=("Reading: " + currentObject))
        cmds.progressBar(gMainProgressBar,
                         edit=1,
                         ii=1,
                         pr=progress,
                         st=("Reading: " + currentObject))
        curLine = (curLine + 1)

        #initialize some more variables
        partsOfLine = []
        partsOfLine = line.split("::")
        typeOfLine = partsOfLine[0]
        lineData = partsOfLine[1]

        ##decision tree of what to do with the line based
        ##on what kind of line it is
        if typeOfLine == "sl":
            currentObject = lineData
            if refReTarget:
                currentObject = jpmReConstObj(currentObject, prefix)
            cmds.select(currentObject,
                        add=selectionAdd)  #, tgl=selectionToggle )
            print "select " + currentObject + " -add " + str(selectionAdd)
        if typeOfLine == "ob":
            currentObject = lineData
            if refReTarget:
                currentObject = jpmReConstObj(currentObject, prefix)
        if typeOfLine == "at":
            currentAttr = lineData
        if typeOfLine == "sv":
            try:
                cmds.setAttr((currentObject + "." + currentAttr),
                             float(lineData))
            except RuntimeError:
                print "I think this means that " + currentObject + "." + currentAttr + " is locked or otherwise unsettable"
        if typeOfLine == "kv":
            ##split the line data into it's individual components
            keyData = []
            keyData = lineData.split(",")

            ##split the keyData up into seperate variables of the appropriate type
            keyTime = float(keyData[0]) + float(placeTime)
            keyValue = float(keyData[1])
            inTangent = keyData[2]
            outTangent = keyData[3]
            inWeight = float(keyData[4])
            outWeight = float(keyData[5])
            inAngle = float(keyData[6])
            outAngle = float(keyData[7])
            weightedTangents = float(keyData[8])
            lockedTangents = float(keyData[9])

            ##make the new key and set it's values and attributes
            cmds.select(cl=1)
            cmds.select(currentObject)
            cmds.setKeyframe(at=currentAttr, v=keyValue, t=keyTime)
            cmds.keyTangent(at=currentAttr,
                            t=(keyTime, keyTime),
                            l=lockedTangents)
            cmds.keyTangent(at=currentAttr,
                            t=(keyTime, keyTime),
                            wt=weightedTangents)
            cmds.keyTangent(at=currentAttr,
                            t=(keyTime, keyTime),
                            itt=inTangent)
            cmds.keyTangent(at=currentAttr,
                            t=(keyTime, keyTime),
                            ott=outTangent)
            cmds.keyTangent(at=currentAttr, t=(keyTime, keyTime), ia=inAngle)
            cmds.keyTangent(at=currentAttr, t=(keyTime, keyTime), oa=outAngle)
            cmds.keyTangent(at=currentAttr, t=(keyTime, keyTime), iw=inWeight)
            cmds.keyTangent(at=currentAttr, t=(keyTime, keyTime), ow=outWeight)

        ##check to see if the user wants to cancel out
        cancel = cmds.progressBar(gMainProgressBar, q=1, ic=1)
        if cancel != 0:
            cmds.progressWindow(e=1, ep=1)
            cmds.progressBar(gMainProgressBar, e=1, ep=1)
            cancel = 1
            break

    ##kill the progress bars
    cmds.progressWindow(ep=1)
    cmds.progressBar(gMainProgressBar, e=1, ep=1)
Exemplo n.º 4
0
def jpmSaveAnimationToFile(name,
                           min,
                           max,
                           saveType,
                           selected=[],
                           keyableAttrs=[],
                           refReTarget=0):
    ##initialize some variables
    safeFileCommand = ""
    reCreateKeyableAttrs = 1
    verboseLevel = 0
    cancel = 0

    ##initialize the progress bars
    progress = 0
    curNumObj = 1
    gMainProgressBar = mm.eval('$tmp = $gMainProgressBar')
    cmds.progressWindow(t="Writing Curves",
                        pr=progress,
                        st="Writing: ",
                        min=0,
                        max=100)
    cmds.progressBar(gMainProgressBar,
                     edit=1,
                     bp=1,
                     st="Writing: ",
                     min=0,
                     max=100)

    ##sanity check to see if anything is selected
    numOfAnimObjs = float(len(selected))
    ##if numOfAnimObjs <= 0:
    ##cmds.error( "Nothing is currently selected. No file created or action taken." )

    ##begin looping through objects
    for object in selected:
        ##sanitize the object name for references and make the object entry line
        #strippedObj = jpmHandleReference_write(object)
        prefix = ref.jpmAmIaReference(object)
        if refReTarget:
            strippedObj = jpmDeConstObj(object, prefix)
        else:
            strippedObj = object
        safeFileCommand = (safeFileCommand + "ob::" + strippedObj + "\n")

        ##progress the progress bars
        progress = ((float(curNumObj) / float(numOfAnimObjs)) * 100)
        cmds.progressWindow(edit=1,
                            ii=1,
                            pr=progress,
                            st=("Writing: " + strippedObj))
        cmds.progressBar(gMainProgressBar,
                         edit=1,
                         ii=1,
                         pr=progress,
                         st=("Writing: " + strippedObj))
        curNumObj = (curNumObj + 1)

        ##find out what attributes are keyable
        if keyableAttrs[0] == "" or reCreateKeyableAttrs == 1:
            keyableAttrs = cmds.listAttr(object,
                                         r=1,
                                         w=1,
                                         k=1,
                                         u=1,
                                         v=1,
                                         m=1,
                                         s=1)
            reCreateKeyableAttrs = 1
        ##begin looping through attributes
        for attr in keyableAttrs:
            ##print attr
            ##write the attribute entry line
            safeFileCommand = (safeFileCommand + "at::" + attr + "\n")
            ##get the current attribute value and write the static value entry line
            staticValue = cmds.getAttr(object + "." + attr)
            safeFileCommand = (safeFileCommand + "sv::" + str(staticValue) +
                               "\n")

            ##get the number of keys in the curve
            cmds.selectKey(clear=1)
            numOfKeys = cmds.selectKey((object + "." + attr),
                                       add=1,
                                       k=1,
                                       t=(min, max))
            keyIndices = []
            keyIndices = cmds.keyframe(q=1, sl=1, iv=1)
            ##begin looping through all the keys on this animation curve
            try:
                for key in keyIndices:
                    ##print key
                    keyValueArray = jpmGetInfoOnAKey(object, attr, key)
                    keyValueString = ""
                    for val in keyValueArray:
                        keyValueString = (keyValueString + val + ",")
                    keyValueString = keyValueString[0:-1]
                    safeFileCommand = (safeFileCommand + "kv::" +
                                       keyValueString + "\n")
            except TypeError:
                print(object + "." + attr + " is not keyed")

        ##check to see if the user wants to cancel out
        cancel = cmds.progressBar(gMainProgressBar, q=1, ic=1)
        if cancel != 0:
            cmds.progressWindow(e=1, ep=1)
            cmds.progressBar(gMainProgressBar, e=1, ep=1)
            cancel = 1
            break

    ##actually write the file out
    saveFile = file(name, "w+")
    saveFile.write(safeFileCommand)
    saveFile.close()

    cmds.progressWindow(ep=1)
    cmds.progressBar(gMainProgressBar, e=1, ep=1)
Exemplo n.º 5
0
def jpmSaveAnimationToFile(name,
                           min,
                           max,
                           saveType,
                           selected,
                           keyableAttrs,
                           refReTarget=False):
    """Save an animation to a JSON formated file"""
    ##initialize some variables
    reCreateKeyableAttrs = True
    verboseLevel = False
    cancel = False

    ##sanity check to see if anything is selected
    numOfAnimObjs = float(len(selected))
    if numOfAnimObjs <= 0:
        cmds.error(
            "Nothing is currently selected. No File created or action taken.")
        return

    ##initialize the progress bars
    progress = 0
    curNumObj = 1
    gMainProgressBar = mm.eval('$tmp = $gMainProgressBar')
    cmds.progressWindow(t="Writing Curves",
                        pr=progress,
                        st="Writing: ",
                        min=0,
                        max=100)
    cmds.progressBar(gMainProgressBar,
                     edit=1,
                     bp=1,
                     st="Writing: ",
                     min=0,
                     max=100)

    ##begin looping through objects
    safeFileDict = {}
    for object in selected:
        ##sanitize the object name for references
        #strippedObj = jpmHandleReference_write(object)
        prefix = ref.jpmAmIaReference(object)
        if refReTarget:
            strippedObj = jpmDeConstObj(object, prefix)
        else:
            strippedObj = object

        ##progress the progress bars
        progress = ((float(curNumObj) / float(numOfAnimObjs)) * 100)
        cmds.progressWindow(edit=1,
                            ii=1,
                            pr=progress,
                            st=("Writing: " + strippedObj))
        cmds.progressBar(gMainProgressBar,
                         edit=1,
                         ii=1,
                         pr=progress,
                         st=("Writing: " + strippedObj))
        curNumObj = (curNumObj + 1)

        ##find out what attributes are keyable
        if keyableAttrs[0] == "" or reCreateKeyableAttrs == 1:
            keyableAttrs = cmds.listAttr(strippedObj,
                                         r=1,
                                         w=1,
                                         k=1,
                                         u=1,
                                         v=1,
                                         m=1,
                                         s=1)
            reCreateKeyableAttrs = 1
        ##begin looping through attributes
        attrDict = {}
        for attr in keyableAttrs:
            ##print attr
            ##get the current attribute value
            staticValue = cmds.getAttr(strippedObj + "." + attr)

            ##get the number of keys in the curve
            cmds.selectKey(clear=1)
            numOfKeys = cmds.selectKey((strippedObj + "." + attr),
                                       add=1,
                                       k=1,
                                       t=(min, max))
            keyIndices = []
            keyIndices = cmds.keyframe(q=1, sl=1, iv=1)

            if keyIndices > 0:
                ##begin looping through all the keys on this animation curve
                try:
                    valuesDict = {}
                    for key in keyIndices:
                        ##print key
                        keyValueArray = jpmGetInfoOnAKey(
                            strippedObj, attr, key)
                        valuesDict[key] = keyValueArray
                except TypeError:
                    print(strippedObj + "." + attr + " is not keyed")
                attrDict[attr] = valuesDict
            elif not keyIndices > 0:
                attrDict[attr] = staticValue
        safeFileDict[strippedObj] = attrDict

        ##check to see if the user wants to cancel out
        cancel = cmds.progressBar(gMainProgressBar, q=1, ic=1)
        if cancel != 0:
            cmds.progressWindow(e=1, ep=1)
            cmds.progressBar(gMainProgressBar, e=1, ep=1)
            cancel = 1
            break
    safeFileDict["AWFileType"] = "anim"

    ##actually write the file out
    saveFile = open(name, 'w')
    json.dump(safeFileDict, saveFile, indent=4, sort_keys=True)
    saveFile.close()

    cmds.progressWindow(ep=1)
    cmds.progressBar(gMainProgressBar, e=1, ep=1)
Exemplo n.º 6
0
def jpmRestoreFromFile(filename, placeTime, placeValue, selectionType,
                       refReTarget):
    ##get the data from the file
    thisFile = open(filename, "r")
    dataDict = json.load(thisFile)
    thisFile.close()

    ##initialize some variables
    currentObject = ""
    currentAttr = ""
    selectionAdd = 0
    selectionToggle = 0
    if refReTarget:
        prefix = ref.jpmAmIaReference(cmds.ls(sl=1)[0])
        if prefix == "0":
            prefix = ""
    else:
        prefix = ""

    ##initialize the progress bars
    progress = 0
    curLine = 0
    objectsInFile = len(dataDict.keys()) - 1
    gMainProgressBar = mm.eval('$tmp = $gMainProgressBar')
    cmds.progressWindow(t="Reading Curves",
                        pr=progress,
                        st="Reading: ",
                        min=0,
                        max=100)
    cmds.progressBar(gMainProgressBar,
                     edit=1,
                     bp=1,
                     st="Reading: ",
                     min=0,
                     max=100)

    ##based on selectionType change some variables
    if selectionType == "add":
        selectionAdd = 1
    if selectionType == "toggle":
        selectionToggle = 1
    if selectionType == "replace":
        cmds.select(cl=1)
        selectionAdd = 1
    if selectionType == "subtract":
        currentSel = cmds.ls(sl=1)

    AWFileType = dataDict["AWFileType"]

    if AWFileType == "anim" or AWFileType == "pose":
        for object in dataDict.keys():
            if object == "AWFileType":
                pass

            ##progress the progress bars
            progress = ((float(curLine) / float(objectsInFile)) * 100)
            cmds.progressWindow(edit=1,
                                ii=1,
                                pr=progress,
                                st=("Reading: " + object))
            cmds.progressBar(gMainProgressBar,
                             edit=1,
                             ii=1,
                             pr=progress,
                             st=("Reading: " + object))
            curLine = (curLine + 1)

            ##If reference retargeting is on, build the reconstructed object name
            if refReTarget:
                #prefix = ref.jpmAmIaReference(object)
                reConstObj = jpmReConstObj(object, prefix)
            else:
                reConstObj = object

            if type(dataDict[object]) == type({}):
                for attribute in dataDict[object].keys():
                    if type(dataDict[object][attribute]) == type({}):
                        #Is an animated value
                        for keyIndex in dataDict[object][attribute].keys():
                            keyValueArray = dataDict[object][attribute][
                                keyIndex]
                            rebuildKey(object, attribute, keyValueArray,
                                       placeTime, placeValue)
                    else:
                        #Is a static value
                        value = dataDict[object][attribute]
                        if cmds.objExists(reConstObj):
                            if cmds.attributeQuery(attribute,
                                                   exists=True,
                                                   node=object):
                                cmds.setAttr(object + "." + attribute, value)

                    ##check to see if the user wants to cancel out
                    cancel = cmds.progressBar(gMainProgressBar, q=1, ic=1)
                    if cancel != 0:
                        cmds.progressWindow(e=1, ep=1)
                        cmds.progressBar(gMainProgressBar, e=1, ep=1)
                        cancel = 1
                        break

    elif AWFileType == "sel":
        savedList = []
        for object in dataDict.keys():
            if object == "AWFileType":
                pass
            else:
                savedList.append(object)

        if selectionType == "add":
            cmds.select(savedList, add=True)
        elif selectionType == "toggle":
            newList = []
            currentSelection = cmds.ls(sl=True)
            cmds.select(newList)
        elif selectionType == "replace":
            cmds.select(clear=True)
            cmds.select(savedList)
        elif selectionType == "subtract":
            newList = []
            currentSelection = cmds.ls(sl=True)
            cmds.select(newList)
        else:
            print "Don't know the selection type"

    ##kill the progress bars
    cmds.progressWindow(ep=1)
    cmds.progressBar(gMainProgressBar, e=1, ep=1)