Skip to main content

Python wrapper for Autodesk Maya FBX plugin

Project description

mayafbx

Warning:

Release 1.0.0 include many API breaking changes and dropped Python 2 support. If you are looking for the legacy version of mayafbx, see this commit and release 0.1.0.

License - MIT Maya Version PyPI - Python Version PyPI - Version Linter - Ruff Types - Mypy CI - Tests Documentation Status

Python wrapper of Maya FBX plugin.

Installation

Install mayafbx with pip.

python -m pip install mayafbx

You can also download and extract mayafbx-<version>.zip from latest release.

The zip archive is created using hatch-zipped-directory and has the following structure:

.
├── LICENSE
├── METADATA.json
├── README.md
└── mayafbx/
    ├── __init__.py
    └── ...

Comparison

Below is an example of how to export an FBX file using standard Maya commands:

from maya import mel

mel.eval("FBXResetExport")  # Reset options.
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')  # '-s' for selected.

And here is how to achieve the same using mayafbx:

from mayafbx import FbxExportOptions, export_fbx

options = FbxExportOptions()
options.animation = True
options.remove_single_key = True
options.cameras = True

export_fbx("C:/outfile.fbx", options, selection=True)

Alternatively, you can write it in a more concise way:

from mayafbx import FbxExportOptions, export_fbx

options = FbxExportOptions(animation=True, remove_single_key=True, cameras=True)

export_fbx("C:/outfile.fbx", options, selection=True)

Quickstart

In this example, we export the animation from a cube and import it back.

import os
import tempfile
from maya import cmds
from mayafbx import (
    FbxExportOptions, 
    FbxImportOptions, 
    MergeMode,
    export_fbx,
    import_fbx, 
)

# 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 = 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")
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 = FbxImportOptions()
options.merge_mode = MergeMode.kMerge
options.animation = True

# Import the previously exported FBX.
import_fbx(filepath, options)

Documentation

See mayafbx documentation for more details.

Contributing

For guidance on setting up a development environment and contributing to the project, see the contributing section.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mayafbx-1.0.0.tar.gz (31.5 kB view details)

Uploaded Source

Built Distribution

mayafbx-1.0.0-py3-none-any.whl (24.4 kB view details)

Uploaded Python 3

File details

Details for the file mayafbx-1.0.0.tar.gz.

File metadata

  • Download URL: mayafbx-1.0.0.tar.gz
  • Upload date:
  • Size: 31.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.0.0 CPython/3.12.3

File hashes

Hashes for mayafbx-1.0.0.tar.gz
Algorithm Hash digest
SHA256 f5e771d9510ad1997cacf13781260c311435d05268513f36306784a615894b39
MD5 a0d7d6d1affcafdb1912a0386886b291
BLAKE2b-256 6c24b11d32fc05b41143659cd5353eb67a382257b76df145946205dda5c38fc5

See more details on using hashes here.

File details

Details for the file mayafbx-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: mayafbx-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 24.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.0.0 CPython/3.12.3

File hashes

Hashes for mayafbx-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 770571e743c7f1d961794fe84d74839831fe9d3fea04c9e1f81bb5f420eeeccb
MD5 fdda53d40de116fbe04d75ad7cd9d62a
BLAKE2b-256 ae11d1899f030c45b71cbd0c4f3c3dcaca3bbea0fc56f608c2f214f0ca992ba5

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page