Right now I'm simply trying to bake out the animation of the controller and copying the animation back onto a locator. The problem is that will the constrained controller is baked out it only the first is baked over the entire time range. So when the controller is suppose to follow whatever was constraining it, it just stays in place.
It's not that I wouldn't be able to directly use data from the XML it's just that it would take time to load to the data back onto the controllers every time the animation is updated. Not only to mention if there are 200 controllers in the scene I would have to go frame by frame for each controller and their attribute and save the data out. It just doesn't seem very efficient.
This is a quick and dirty version of my code. The overall code uses just simple maya commands, which is why I find it very odd to be having such an issue.
import sys, os.path
import maya.standalone as st
##Start Maya Standalone
st.initialize(name='python')
import maya.cmds as cmds
path= 'animatedScene.ma'
##Open File
cmds.file( path, f=1, o=1)
path= os.path.normpath( path)
#print( path)
##Open File
cmds.file( path, f=1, o=1)
##Grab Start Frame
startTime= int( cmds.playbackOptions( q=True, min=True))
#print( startTime)
##Grab End Frame
endTime= int( cmds.playbackOptions( q=True, max=True))
print( endTime)
##Grab all sets
setList=
cmds.ls( et= 'objectSet' )
#print( setList)
for set in setList:
ctrl_list= cmds.sets( set, q= 1)
#print( ctrl_list)
##Bake controllers from Set Lister
for ctrl in ctrl_list:
##Bake out controls
cmds.bakeResults( ctrl, simulation=0, t=( startTime, endTime), shape=1, dic= 0, pok= 0)
##Copy animation from controller to locator
for ctrl in ctrl_list:
##Fix namespace
newCtrl= ctrl.replace( ':', '_NmSp_')
#print( newCtrl)
##Create locator
sceneAnimLoc= cmds.spaceLocator( n= newCtrl+'_animLoc', p=[0, 0, 0] )[0]
#print( sceneAnimLoc)
##Grab attributes
attrList= cmds.listAttr( ctrl, k= 1, u= 1)
#print( ctrl, attrList)
for attr in attrList:
newAttr= attr.replace( ':','_NmSp_')
newAttr= newCtrl+'_'+ newAttr
#print( newAttr)
##Create attribute for locator
cmds.addAttr( sceneAnimLoc, ln= newAttr, at= 'double', k= 1)
##Check if controller attribute is keyed
checkKey= cmds.keyframe( ctrl, q= 1, at= attr)
#print( ctrl, attr, checkKey)
if( checkKey):
##Copy key from at Controller attribute
cmds.copyKey( ctrl, time=[], f=[], attribute= attr)
##Paste Controller Attribute onto SceneAnim Loc
cmds.pasteKey( sceneAnimLoc, attribute= newAttr)
##Save File
cmds.file( rn= 'baked_animScene.mb')
cmds.file( s=1, f=1)
currentFile= cmds.file( q=1, exn=1)
print( currentFile)