Category Archives: Python Scripts

Maya to FBX Batch Export

UPDATE(30/7/13) If you’ve found this post and you’re thinking of using this code please try this instead. It’s my much more reliable and feature-rich exporter. The one below works fine, but it’s really just a check to see if batch exporting is possible. Once I’d established that I made the thing that’s on the other end of the link above.

A simple FBX batch export script, useful for exporting multiple animations from a single file. You can download the .py file here. It should be noted however that this script isn’t tested anywhere near as much as it should be, so back up your work before running it.

# James Kyle 12/3/13,
# Maya to UDK batch exporter script
# Contains code borrowed from Mark Jackson's blog, which can be found here:

# Warning!
# This is probably a bit buggy and isn't tested. Save your work before you use it!
# I take no responsibility for any data lost as a result of this script. Use at your own risk! 🙂

# Instructions:
# Edit the Tuple data below with your own filenames, start frames and end frames.
# Select the mesh/meshes and the root joint of the joint hierarchy you want to export.
# Run script!

# Important importing...
import maya.cmds as cmds
import maya.mel as mm

# Lists of animation names, start frames and end frames.
# Add/remove as required.
exportNames = ("BE_idle", "BE_fistBump", "BE_pickup")
exportStartFrame = (1, 32, 300)
exportEndFrame = (23, 70, 333)

# This code selects the joints and meshes only. This isn't my code!
# Original author credit at the top of the script.

#find all joints

#find your Skinned Geo
for skin in cmds.listConnections(joints,type='skinCluster'):
    if skin:
        if meshTransform not in meshes:
# Borrowed code ends here.

for x in range(len(exportNames)):
    print exportNames[x]
    # Select the mesh and joints to export,meshes)

    # FBX Exporter options. Set as required.
    # You can find a reference guide here:
    # Just add/change what you need.

    # Geometry
    mm.eval("FBXExportSmoothingGroups -v true")
    mm.eval("FBXExportHardEdges -v false")
    mm.eval("FBXExportTangents -v false")
    mm.eval("FBXExportSmoothMesh -v true")
    mm.eval("FBXExportInstances -v false")
    mm.eval("FBXExportReferencedContainersContent -v false")
    # Animation
    mm.eval("FBXExportBakeComplexAnimation -v true")
    mm.eval("FBXExportBakeComplexStart -v "+str(exportStartFrame[x]))
    mm.eval("FBXExportBakeComplexEnd -v "+str(exportEndFrame[x]))
    mm.eval("FBXExportBakeComplexStep -v 1")
    # mm.eval("FBXExportBakeResampleAll -v true")
    mm.eval("FBXExportUseSceneName -v false")
    mm.eval("FBXExportQuaternion -v euler")
    mm.eval("FBXExportShapes -v true")
    mm.eval("FBXExportSkins -v true")
    # Constraints
    mm.eval("FBXExportConstraints -v false")
    # Cameras
    mm.eval("FBXExportCameras -v false")
    # Lights
    mm.eval("FBXExportLights -v false")
    # Embed Media
    mm.eval("FBXExportEmbeddedTextures -v false")
    # Connections
    mm.eval("FBXExportInputConnections -v false")
    # Axis Conversion
    mm.eval("FBXExportUpAxis y")

    # Export!
    mm.eval("FBXExport -f "+exportNames[x]+".fbx -s")

Building the UI in Maya Python

Character rig UI work in progress

As you can see from the image above I’m finally starting to get somewhere with my Python. I’m building a reasonably well laid out UI and today managed to map my head around how Maya’s implementation in Python does querying and editing of UI element properties (e and q tags not listed in the Maya Python reference library other than which can be applied to other methods/parameters.)

It’s tough going but by tomorrow afternoon I’ll be ready to begin on actually automating something. Getting that first one out the way will probably take a while as I’ll need to lear a lot of stuff to get there, but once it’s out the way I’ll likely have the tools I need to do the rest much more quickly. I’m starting with the legs, excluding the feet, setting up a IKRP on the legs, creating the locators/control shapes and arranging the hierarchy properly. I’ll post again around this time next week with the latest progress and changes I’ve made to my plans.