mayafbx
A Python wrapper for the Maya FBX plugin
Documentation • API Reference • PyPI • GitLab • GitHub • Contributing • ChangelogInstallation¶
Comparison¶
Below is an example of exporting an FBX file using standard Maya commands:
from maya import mel
mel.eval("FBXResetExport")
mel.eval("FBXProperty Export|IncludeGrp|Animation -v true")
mel.eval("FBXProperty Export|IncludeGrp|Animation|ExtraGrp|RemoveSingleKey -v true")
mel.eval("FBXProperty Export|IncludeGrp|CameraGrp|Camera -v false")
mel.eval('FBXExport -f "C:/outfile.fbx" -s')
Here's how to achieve the same result with mayafbx:
import mayafbx
options = mayafbx.FbxExportOptions()
options.animation = True
options.remove_single_key = True
options.cameras = True
mayafbx.export_fbx("C:/outfile.fbx", options, selection=True)
Alternatively, all fields can be passed directly to the constructor as kwargs:
import mayafbx
options = mayafbx.FbxExportOptions(animation=True, remove_single_key=True, cameras=True)
mayafbx.export_fbx("C:/outfile.fbx", options, selection=True)
Example¶
This example shows how to export animation from a cube and import it back.
import os
import tempfile
from maya import cmds
import mayafbx
# start from an empty scene
cmds.file(new=True, force=True)
# create a cube with 2 keyframes
cube = cmds.polyCube()[0]
cmds.setKeyframe(cube, attribute="translateX", time=1, value=0)
cmds.setKeyframe(cube, attribute="translateX", time=24, value=10)
# prepare options to export baked animation
options = mayafbx.FbxExportOptions()
options.animation = True
options.bake_animation = True
options.bake_resample_all = True
# export the scene as FBX
filepath = os.path.join(tempfile.gettempdir(), "testcube.fbx")
mayafbx.export_fbx(filepath, options)
# remove all keys from the cube
cmds.cutKey(cube, attribute="translateX", option="keys")
# prepare options to import animation back to the cube
options = mayafbx.FbxImportOptions()
options.merge_mode = mayafbx.MergeMode.kMerge
options.animation = True
# import the previously exported FBX
mayafbx.import_fbx(filepath, options)
Contributing¶
Contributions of any kind are welcome. Please open an issue, or read the contribution guidelines and open a merge request.