FBX Export with animation in python maya.
py
def export_one_fbx(
namespace,
out_path,
animation_only=False,
export_cameras=False,
bake_complex_animation=False,
bake_resample_animation=False,
bake_complex_start_frame=0,
bake_complex_end_frame=0,
bake_complex_step=1,
apply_constant_key_reducer=False,
fbx_version='FBX201600'
):
"""Export camera to fbx.
:param namespace: Namespace to export.
:type namespace: str
:param out_path: Out export path.
:type out_path: str
:param animation_only: Export animation only, default to False.
:type animation_only: bool, optional
:param export_cameras: Include or exclude cameras in your FBX export, default to False.
:type export_cameras: bool, optional
:param bake_complex_animation: Bake animation at export time, default to False.
:type bake_complex_animation: bool, optional
:param bake_resample_animation: Bake even the supported animated elements, default to False.
:type bake_resample_animation: bool, optional
:param bake_complex_start_frame: Start frame range to bake, default to 0.
:type bake_complex_start_frame: int, optional
:param bake_complex_end_frame: End frame range to bake, default to 0.
:type bake_complex_end_frame: int, optional
:param bake_complex_step: Custom bake step, default to 1.
:type bake_complex_step: int, optional
:param apply_constant_key_reducer:
True: This eliminates constant keys on a FCurve and helps to reduce the size of resampled FCurves, especially Scale.
False: ensures that the animation data is not filtered.
default to False.
:type apply_constant_key_reducer: bool, optional
:param fbx_version: FBX Version, default to 'FBX201600'.
:type fbx_version: str, optional
"""
# Saved current selection.
old_selected_objects = cmds.ls(sl=True, long=True) or []
# Select our object
cmds.select(namespace)
# To avoid conflict with local custom export config.
cmds.FBXResetExport()
cmds.FBXExportAnimationOnly('-v', animation_only)
cmds.FBXExportBakeResampleAnimation('-v', bake_resample_animation)
cmds.FBXExportBakeComplexAnimation('-v',bake_complex_animation)
cmds.FBXExportBakeComplexStart('-v', bake_complex_start_frame)
cmds.FBXExportBakeComplexEnd('-v', bake_complex_end_frame)
cmds.FBXExportBakeComplexStep('-v', bake_complex_step)
cmds.FBXExportApplyConstantKeyReducer('-v', apply_constant_key_reducer)
cmds.FBXExportCameras('-v', export_cameras)
cmds.FBXExportFileVersion('-v', fbx_version)
cmds.FBXExport('-s', '-f', out_path)
# Reapply old selections.
cmds.select(old_selected_objects)