Maya Python API 3.0
a.k.a. "Maya Python API 3.0"
An alternative set of bindings for the C++ API of Maya 2018-2023.
Why?
That's what this repository is for.
The bindings should aim to match Maya Python API 2.0 as closely as possible, with the exception of being open source and to never allow Maya to crash as a result of calling any function or method.
import cmdc
typ = cmdc.TypeId(16)
mat4 = cmdc.Matrix()
mat4 *= cmdc.Matrix().inverse()
vec3 = cmdc.Vector()
vec3.x = 6
quat = cmdc.Quaternion(angle=0.5, axis=cmdc.Vector(1, 0, 0))
mat4 *= quat
# No need for MString
string = str()
# Modify the Maya scene graph
from maya import standalone
standalone.initialize()
fn = cmdc.FnDependencyNode()
r = fn.create("reverse", name="myReverse")
print(fn.name())
# This next line really shouldn't work, should require MFnDagNode
t = fn.create("transform", name="myTransform")
print(fn.name())
print("Success")
Code completion working in Visual Studio Code with Pylance
Type Checking working in Visual Studio Code with Pylance
cmdc
should have the same advantages over 1.0 as 2.0, and more.
cmdc
should be faster or as fast as API 2.0
cmdc
comes with fully type annotated stubs, making it easy to set up code completion as well as type checking.It'll work, but won't have half the things you'll need to do anything of use in Maya. The current source is enough to illustrate (1) how to expose types, (2) how to expose function sets and (3) how to deal with passing MObject references around.
File | Description |
---|---|
cmake/ |
CMake setup for Maya and Python libraries |
docker/ |
Docker containers for building in linux |
os/ |
The missing Python libraries for all operating systems and Python versions |
pyblind11/ |
The pybind11 source |
scripts/ |
Code-generation |
src/ |
C++ source for the pybind11 bindings |
tests/ |
Tests for bound methods and types |
Build requirements:
cmake -B ./build -DCMAKE_BUILD_TYPE=Release -DMAYA_VERSION=2020 -DMAYA_DEVKIT_ROOT="path/to/devkit"
cmake --build ./build --config Release
This should build on any platform, for any Maya with Python available. Including 2023.
Interested in helping out? Here's how to do it.
FAQ
Do I need to know C++?
Not really! What we're doing here is mostly busy-work, filling in the many functions exposed by the Maya API. Most if not all trickery has already been done in other functions, so copy/paste is a valid option.
I don't have any other questions?
Great, then here's what's next.
# Tell cmdc about where your devkit is
$env:DEVKIT_LOCATION="C:\maya-devkit"
# Clone the big jeeves out of this repository
git clone https://github.com/mottosso/cmdc.git
cd cmdc
# Either write your own header from scratch..
# ..or generate some boiler plate of your favourite header!
mayapy ./scripts/parse_header.py MFnDagNode.h
From here, you'll have a freshly generated header file, ready to fill in. As you fill things in, see build above for how to iterate and once you're happy you're welcome to submit a Pull Request!