https://github.com/tahv/mayafbx
Python wrapper for the Maya FBX plugin
https://github.com/tahv/mayafbx
fbx maya python
Last synced: 10 months ago
JSON representation
Python wrapper for the Maya FBX plugin
- Host: GitHub
- URL: https://github.com/tahv/mayafbx
- Owner: tahv
- License: mit
- Created: 2021-02-14T21:51:14.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2024-05-30T22:14:06.000Z (about 2 years ago)
- Last Synced: 2025-09-17T04:16:08.018Z (10 months ago)
- Topics: fbx, maya, python
- Language: Python
- Homepage: https://mayafbx.readthedocs.io
- Size: 34.2 KB
- Stars: 25
- Watchers: 1
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
[mayafbx-documentation]: https://mayafbx.readthedocs.io/latest
[mayafbx-license]: https://github.com/tahv/mayafbx/blob/main/LICENSE
[mayafbx-repo]: https://github.com/tahv/mayafbx
[mayafbx-pypi]: https://pypi.org/project/mayafbx
[ruff-repo]: https://github.com/astral-sh/ruff
[mypy-repo]: https://github.com/python/mypy
[mayafbx-workflow-tests]: https://github.com/tahv/mayafbx/actions/workflows/tests.yml
[mayafbx-latest-release]: https://github.com/tahv/mayafbx/releases/latest
[mayafbx-contributing]: https://mayafbx.readthedocs.io/latest/contributing.html
# 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](https://github.com/tahv/mayafbx/tree/95d52a61bdefd84c90b9822b2ccb829da89626a8)
> and release [`0.1.0`](https://github.com/tahv/mayafbx/releases/tag/0.1.0).
[][mayafbx-license]
[][mayafbx-pypi]
[][mayafbx-pypi]
[][mayafbx-pypi]
[][ruff-repo]
[][mypy-repo]
[][mayafbx-workflow-tests]
[][mayafbx-documentation]
Python wrapper of Maya FBX plugin.
## Installation
Install `mayafbx` with pip.
```bash
python -m pip install mayafbx
```
You can also download and extract `mayafbx-.zip` from [latest release][mayafbx-latest-release].
The zip archive is created using
[`hatch-zipped-directory`](https://github.com/dairiki/hatch-zipped-directory)
and has the following structure:
```text
.
├── LICENSE
├── METADATA.json
├── README.md
└── mayafbx/
├── __init__.py
└── ...
```
## Comparison
Below is an example of how to export an FBX file using standard Maya commands:
```python
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`:
```python
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:
```python
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.
```python
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][mayafbx-documentation] for more details.
## Contributing
For guidance on setting up a development environment and contributing to the project,
see the [contributing][mayafbx-contributing] section.