• Stars
    star
    120
  • Rank 295,983 (Top 6 %)
  • Language
    C
  • License
    MIT License
  • Created over 3 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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?

  • What if Maya's Python bindings were open source?
  • What if whenever Maya crashed, you'd get more than an opaque stack trace?
  • What if you were able to see why a crash occurred, and what line it occurred on?
  • What if you could address bugs in the bindings yourself?
  • What if you could add missing members yourself?
  • What if there were bindings for Maya that made it impossible to crash Maya from Python?
  • What if setting up code completion and type checking was easy?

That's what this repository is for.


Example

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


Goal

cmdc should have the same advantages over 1.0 as 2.0, and more.

  • Array types are full Python sequences, including slice support.
  • Methods which take Maya array parameters will always also take native Python sequences, such as arrays and tuples.
  • The outputs of methods are always returned in their return values, not through their parameter lists.
  • Methods which return multiple values (e.g. MFnFluid.getResolution) return them as a tuple or list, eliminating the need for MScriptUtil.
  • Object attributes are preferred over rather than set/get methods. For example you can now write array.sizeIncrement=64.
  • There are more types of exceptions used when methods fail. Not everything is a RuntimeError, as was the case in the old API.
  • cmdc should be faster or as fast as API 2.0

    Reference

  • cmdc comes with fully type annotated stubs, making it easy to set up code completion as well as type checking.

Status

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.


Repository

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

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.


Contributing

Interested in helping out? Here's how to do it.

  1. Get a free compiler, like Visual Studio 2019 for Windows
  2. Download and unzip a Maya devkit (scroll down)
  3. Clone this repository
  4. Write your header file
  5. Submit a pull-request
  6. Profit

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!

More Repositories

1

Qt.py

Minimal Python 2 & 3 shim around all Qt bindings - PySide, PySide2, PyQt4 and PyQt5.
Python
915
star
2

cmdx

Fast and persistent subset of maya.cmds
Python
191
star
3

allzpark

Package-based application launcher for VFX and games production
Python
184
star
4

Maya-Environment-Variables

All available (but undocumented) environment variables in Autodesk Maya
160
star
5

docker-maya

Dockerfile for Maya
Dockerfile
119
star
6

maya-sniffer

Treemap visualisation of Maya scene files
Python
90
star
7

apiundo

Undo/Redo support for Maya Python API 2.0
Python
67
star
8

qargparse.py

Build settings-style graphical user interfaces for Python with argparse syntax
Python
48
star
9

be

minimal directory and environment management system for collaborative creative projects
Python
47
star
10

rez-for-projects

An example and exploration of how and whether to use Rez for project configuration management
Python
46
star
11

docker-deadline

Docker images for Thinkbox Software Deadline
Mathematica
40
star
12

Qt5.py

Minimal Python 2 & 3 shim around PySide2 and PyQt5
Python
33
star
13

rez-pipz

Pip for Rez - Install any Python package from PyPI as a Rez package
Python
29
star
14

rez-scoopz

Scoop for Rez - Install Windows software from a selection of 500+ packages and counting
Python
25
star
15

ncloth-reference

Joel Stutz's excellent nCloth reference, revived! https://mottosso.github.io/ncloth-reference
HTML
24
star
16

maya-test

Run your Python script, in every version of Maya
Python
20
star
17

learn-cinder

Notes and examples for getting started with libcinder - https://mottosso.gitbooks.io/cinder/content/
C++
19
star
18

aTools

Alan Camilo's animation toolkit
Python
17
star
19

docker-cgwire

Docker container for https://cg-wire.com
15
star
20

pymel-mock

Accelerate Maya start-up time and prevent accidental use
Python
10
star
21

rez-localz

Package localisation for Rez
Python
10
star
22

docker-usd

Unofficial Dockerfile for Pixar's USD
9
star
23

maya-multicapture

Capture multiple cameras at once
Python
9
star
24

mayabase-centos

Maya base on CentOS 6
8
star
25

maya_python_c_extension

Fork from sonictk
Shell
8
star
26

cs50x

Introduction to Computer Science
C
7
star
27

iscompatible

Python versioning with PyPI requirements.txt syntax
Python
7
star
28

maya-attribute-explorer

Explore available attributes of any node in Maya
Python
6
star
29

deplish

Depends + Pyblish
Python
5
star
30

rez-bundles

Companion repository to rez-for-projects
Python
4
star
31

vfxplatform-docker

Unofficial docker image with apps according to VFX Reference Platform
4
star
32

djv

Mirror of http://djv.sourceforge.net/
C++
3
star
33

pyblish-cpp

C++ implementation of Pyblish QML
C++
3
star
34

avalon-launcher2

Experimental Launcher for the Avalon pipeline
CSS
3
star
35

feather

3d polygon modeller based off of Wings3d
C++
3
star
36

yappi

GitHub clone of https://bitbucket.org/sumerc/yappi
Python
3
star
37

maya-memorycache

Produce caches that remember the state in which they were produced
2
star
38

feather-plugins

Collection of Feather plugins
C++
2
star
39

docker-maya2016

Dockerfile for Maya 2016
2
star
40

rez-installz

Native Rez package manager
2
star
41

PersistentPython

Persistent Python interpreter for Sublime Text 3
Python
2
star
42

mayaGeometryShader

Non-working example of a geometry shader in Maya
Python
2
star
43

rez-internal-example

An example project for rez-for-projects
Python
2
star
44

postal

Source for Postal (1)
C++
2
star
45

from-nand-to-tetris-I

From NAND to Tetris I
Assembly
2
star
46

badshell

Python
2
star
47

add

minimal, cross-platform additive environments for your shell.
Shell
2
star
48

maya-corollary

Client + Server model of a Maya deformer via ZeroMQ
C++
2
star
49

sublime-python-exec

Run Python in Sublime Text without saving
Python
1
star
50

bleed

An Avalon demo profile for Allzpark
Python
1
star
51

be-presets

be presets
1
star
52

be-ad

be project preset for ads
1
star
53

mayabase-ubuntu

Maya base on Ubuntu 14.04
1
star
54

mygame

An OpenGL game
C++
1
star
55

be-helloworld

Test preset for be
1
star
56

ftrack

ftrack evaluation
1
star
57

allzparkdemo

Demo content for Allzpark
Python
1
star
58

docker-dance

Dockerfile for DANCE
1
star
59

maya-procedural-rigging

A Wiki and Issue tracker for a rigging technique.
1
star
60

arsenalsuite

Clone of https://code.google.com/archive/p/arsenalsuite/
HTML
1
star
61

kabaret

Kabaret, https://pythonhosted.org/kabaret/
Python
1
star
62

blur

CS50x Final Project
C
1
star