Python wrapper for Autodesk Maya FBX plugin
Project description
mayafbx
Warning:
Release
1.0.0include many API breaking changes and dropped Python 2 support. If you are looking for the legacy version ofmayafbx, see this commit and release0.1.0.
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f5e771d9510ad1997cacf13781260c311435d05268513f36306784a615894b39
|
|
| MD5 |
a0d7d6d1affcafdb1912a0386886b291
|
|
| BLAKE2b-256 |
6c24b11d32fc05b41143659cd5353eb67a382257b76df145946205dda5c38fc5
|
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
770571e743c7f1d961794fe84d74839831fe9d3fea04c9e1f81bb5f420eeeccb
|
|
| MD5 |
fdda53d40de116fbe04d75ad7cd9d62a
|
|
| BLAKE2b-256 |
ae11d1899f030c45b71cbd0c4f3c3dcaca3bbea0fc56f608c2f214f0ca992ba5
|