How do I export just the animation layer in Maya Python?

I’m trying to export an animation layer as a MayaBinary file in python.
I can’t find any clear examples on how to do it, has anyone tried it before?

My current work-a-round is to use this:

command = str('animLayersSaveExportClbc "' + export_filepath_mb + '.mb" "mayaBinary";')

However this breaks all future standard exports. When I tried exporting a selection as an FBX it would not work correctly until I closed and reopened Maya. I’m looking for a less tedious solution if possible.

Stealing a suggestion from @VVVSLAVA :

If a specific mel command does not seem to have a maya.cmds equivalent,
you can always use whatIs("melCommand") to find the source file

// Result: Mel procedure found in: C:/Program Files/Autodesk/Maya2022/scripts/startup/layerEditor.mel //

looking there we see that animLayersSaveExportClbc is just a wrapper for the file command

global proc animLayersSaveExportClbc(string $file, string $type)
	file -exportSelected -channels 0 -constructionHistory 0 -expressions 0 -constraints 0 -type $type $file;

so you can likely accomplish the same with maya.cmds.file()

1 Like

YES! thanks a bunch I believe I have figured out the proper method now.

in addition to this file export I also need to select the proper objects that are not normally selected when simply clicking on the animLayer. This is how it was done.

targetLayer = "your_selected_animLayer"
export_filepath = "C:/Users/person/Desktop/testFolder/testing01"
cmds.animLayer(targetLayer, e=True, writeBlendnodeDestinations=True)
layerCurves = cmds.animLayer(targetLayer, q=True, animCurves=True)
layerBlendNodes = cmds.animLayer(targetLayer, q=True, blendNodes=True), add=True, noExpand=True)

for c in layerCurves:, add=True)

for blendNode in layerBlendNodes:, add=True)

cmds.file(export_filepath + '.mb', type="mayaBinary", exportSelected=True, channels=False, constructionHistory=False, expressions=False, constraints=False)


I still need to do some more testing but I got a good feeling about this :slight_smile:

1 Like