splinecraft
4/5/2017 - 8:12 PM

From http://www.conghal.com/blog/ bake quadruped anim to locators to use pivot control (step 1)

From http://www.conghal.com/blog/ bake quadruped anim to locators to use pivot control (step 1)

# create a locator for each selected control
# bake worldspace matrix to locator for each key in range

import maya.cmds as cmds

sel = cmds.ls (sl=True)
objLocList = []
ctrlSet = cmds.sets(em=True, n="bakedWsCtrlsSet")
locSet = cmds.sets(em=True, n="bakedWsLocsSet")

for obj in sel:
    objXform = cmds.xform (obj, q=True, m=True, ws=True)
    loc = "|" + cmds.spaceLocator (n = (obj + "_locator"))[0]
    cmds.xform (loc, m=objXform, ws=True)
    objLocList.append((obj,loc))
    cmds.sets(obj, add=ctrlSet)
    cmds.sets(loc, add=locSet)

rangeMin = int(cmds.playbackOptions(q=True, min=True))
rangeMax = int(cmds.playbackOptions(q=True,max=True))

initTime = cmds.currentTime(q=True)
autoKeyState = cmds.autoKeyframe(q=True, st=True)
cmds.autoKeyframe(st=False)

for t in range(rangeMin, rangeMax + 1):
    cmds.currentTime (t)
    for (trgtObj, loc) in objLocList:
        trgtXform = cmds.xform (trgtObj, q=True, m=True, ws=True)
        cmds.xform (loc, m=trgtXform, ws=True)
        cmds.setKeyframe(loc, at=["t","r","s"], rk=True)

cmds.currentTime(initTime) 
cmds.select(sel)

cmds.autoKeyframe(st=autoKeyState)