Maya Stand Alone Issue, Baking Animation

781 views
Skip to first unread message

Carlo

unread,
May 30, 2012, 11:43:39 AM5/30/12
to python_in...@googlegroups.com
Hey, I'm currently using Maya Standalone to baked out a list of controllers on a rig and copy their animation onto a locator. When I run the script any controllers that have key frames on them will transfer over, but if a controller is constrained to an object the script will only copy the first frame of its animation. I tried running the same script in the Maya and was able to copy the animation of all controllers, constrained or not. So is there an issue with Maya Standalone that prevents it from baking out the animation of a constrained object?

If that is the case then is there a way I can store the animation of the selected controllers, I was thinking about used Maya API, but I'm not to familiar with it and not to sure exactly where to start. Any help would be much appreciate. I also thought to store the information onto an xml file, but if a rig have 50 controllers and each have 10 attributes, and there's 100 frames in the shot, well that would just take an crazy about of time to write out and read back to the controllers and key them all for every frame. Also it doesn't seem very efficient or practical.

The reason why I can't just use the script in regular Maya is that I have to copy animation for several files and need a way to batch multiple files out.

I hope what I am saying makes sense, any help would be very much appreciate. Thank you. 

Justin Israel

unread,
May 30, 2012, 12:48:10 PM5/30/12
to python_in...@googlegroups.com, python_in...@googlegroups.com
Would you be able to provide a small reproducible example so that this can be tested? 
Also, what is the circumstance where you are able to get the data you need and write it to XML, but not use it directly?  


Carlo

unread,
May 30, 2012, 3:03:47 PM5/30/12
to python_in...@googlegroups.com
Hey Justin,

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)

Damon Shelton

unread,
May 30, 2012, 3:15:23 PM5/30/12
to python_in...@googlegroups.com, python_in...@googlegroups.com
Try setting simulation to 1 for bakeResults.


--

Carlo

unread,
May 30, 2012, 3:36:59 PM5/30/12
to python_in...@googlegroups.com
Hey Damonshelton,

I've tried that flag before and still had the same problem. Also the default on that flag is already set to 1. Thanks though.

Jesse Capper

unread,
May 30, 2012, 10:18:05 PM5/30/12
to python_inside_maya
I have used bakeResults in maya.standalone without issue on parent/
point/orient constrained attributes, so I know it can work (I know
that doesn't help much).
Is the animation not baking for the full range on the constrained
attributes? Or is it just not copying for the full range?

Re your concern with XML:

"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"

The keyframe command can query an entire animation curve, so assuming
you have a list of the attributes you wanted to query for a given
object:

obj = 'locator1'
attrs = ['tx', 'ty', 'tz']
for attr in attrs:
# When querying time and value (tc/vc), the command returns a list
# of [time, value, time, value, time, value, ...]
keys = cmds.keyframe(obj, q=True, at=attr, t=[], vc=True, tc=True)

Unfortunately if you pass it a list of attributes maya doesn't
distinguish between them in the resulting list so as far as I know you
have to do it one attribute at a time.
Assuming you're doing this to baked keys, you don't need to worry
about tangents, but if you weren't you would have to use
cmds.keyTangent as well for the weight/angle/type of each tangent. I'm
not saying you should necessarily go down this route, just that it's
not as cumbersome as you seem to have assumed.

Carlo

unread,
May 31, 2012, 1:38:49 AM5/31/12
to python_in...@googlegroups.com
Yeah the problem is that its not backing the full range of animation on the constrained objects, it only does the first frame. Yet if I run the same code while maya is open it works just fine. I'm not sure where the problems is occurring and I have tried many different flag options to see if I had something marked wrong.

And I agree with you it wouldn't be that horrible, but it would just ad another step in the process. Not to mention that the baking keys of a constrained object still is working for me.

I do appreciate the effort and time given to try to help me out though. I'll keep on trying to figure something out with this maya.standalone issue.

I'm not to sure if I install the standalone wrong, or if I am not using it correctly, because I have notice. That if I try to run the standalone on any other computer at work it crashes while opening the file. Yet on my computer it can open it up perfectly fine..

Jesse Capper

unread,
May 31, 2012, 2:36:52 AM5/31/12
to python_inside_maya
I tried your script out on a simple scene with a cylinder parent
constrained to an animated locator, and the cylinder added to a set,
and it baked out fine.

I threw the scene I used in a pastebin: http://pastebin.com/DduyZz1L
If you feel like it try that out and see if it works for you (I had to
add a boolean check of ctrl_list before trying to loop through it,
otherwise I didn't change your script).

Carlo

unread,
Jun 1, 2012, 2:22:06 PM6/1/12
to python_in...@googlegroups.com
Arite thank you, I'm going to give that a shot in a few. Also, what is the best way of running maya standalone? I've been making a bat file and executing it that way, but when I try that same method on other computers it crashes?

Justin Israel

unread,
Jun 1, 2012, 3:03:00 PM6/1/12
to python_in...@googlegroups.com
Crashes with what? I do something similar in bash scripts like this:

    #!/bin/bash
    /Applications/Autodesk/maya2012/Maya.app/Contents/bin/mayapy /path/to/script.py "$@"

And then script.py might contain:

    if __name__ == "__main__":
import maya.standalone
maya.standalone.initialize(name="python")

import sys
print "Args:", sys.argv[1:]



On Fri, Jun 1, 2012 at 11:22 AM, Carlo <carl...@gmail.com> wrote:
Arite thank you, I'm going to give that a shot in a few. Also, what is the best way of running maya standalone? I've been making a bat file and executing it that way, but when I try that same method on other computers it crashes?

--

Carlo

unread,
Jun 1, 2012, 3:20:07 PM6/1/12
to python_in...@googlegroups.com
It crashes every time I try to open a file. And I don't believe it the file that has a problem, because when I do the same script on my computer it runs fine, but if I try to run it on other computers it will run mayapy and initialize but the second it tries to open a scene file it crashes. So I don't if I installed something extra on my computer or if I'm just missing a certain step. I'm completely new to all this, so I'm sorry if my questions/ or replies are a bit vague.
Reply all
Reply to author
Forward
0 new messages