At work we’re moving from a MotionBuilder pipeline to Maya, which I’m responsible for creating. One of the tasks on the list I was handed was to move animated takes out of MB and into Maya so that all exported files can be run through the same export steps, and also so that moving forwards animators would have the same tools for working on older animations as they will on files using my new rig.

I have Maya Creation Suite 2012 on my work machine, which is touted as being able to seamlessly transfer data between the included apps– Maya, MotionBuilder, and Mudbox. I haven’t had need to open Mudbox yet, but in my limited testing so far the Human IK rigs never come through properly from MB to Maya and on the Maya side the HIK characterization gets broken. This means that to do any animation fixes or retargeting inside Maya, the characterization needs to be deleted and rebuilt. Also funny: the automatic naming templates in Maya don’t always work, making recharacterization a tedious manual process. Keyed transforms (joints, etc.) and meshes come through just fine, however, with all skinning and materials in tact. Updating previously-sent objects did not.

Apart from all that, the first file I’ve been working on has 50 animations in it. I didn’t relish the idea of converting all of them by hand, so I set about seeing what’s possible on the scripting side.

The FBX import/export plugin comes with a number of commands for massaging how files are read in. A full list of the commands is on Autodesk’s site. Note that the Python versions of these functions fail; I think they’re being generated improperly at plugin load. Could be that I’m just not calling them properly; I didn’t bug-hunt because I found doing the HIK post-import steps didn’t work in Python, either.

I’ve written more MEL in the last two days than I have in the last four years, not that it’s a lot of code!

The important commands for what I needed are:

FBXRead -f [filename] — Doesn’t do any loading. Instead, it sets the specified file as the source for all queries.

FBXGetTakeCount — Self-explanatory; on the file I was editing it returned 50.

FBXGetTakeName [index]: returns the name of the take for a specified index. The indices are 1-based. I saved all of these in a string array.

FBXImportSetMayaFrameRate -v [true|false] — Important in my case because the animation was all at 30 frames per second, while Maya is usually set to 24.

FBXImportFillTimeline -v [true|false] — Makes sure the timeline length matches the length of the imported animation (although see below for a gotcha)

FBXImport -file "c:/myfile.fbx" -t [take index] — Does the actual loading of the scene. By specifying a take index, you can be sure to get only the animation you want.

With this information, I was able to loop through the animations in the FBX and, after a bit of post-import processing, spit out a series of .ma files.

There were few gotchas. One problem was that while the script was running, sometimes the setting for having the FBX file’s time length override the same in Maya would get truncated– the animation length got set but the [bar that shortens the animation] would get set to half the length. I couldn’t replicate the issue running the MEL script in small chunks. A call to playbackOptions in my loop fixed this, but it’s still weird.

Part two of this discussion will be about man-handling Maya’s Human IK in a batch process.