Writing a Maya Python C++ Extension

I’ve written my first tutorial for 2018. It’s been a while, since I’ve been busy learning some other things and getting caught up with other non-programming related issues.

This time, it’s inspired by a topic that has been brought up several times by several acquaintances of mine; the relative lack of completeness surrounding the Maya Python API 2.0. So, instead of endlessly hearing complaints about it, I’d like to present people with the tools they need to get the work done. By themselves, if necessary.

Here’s how you write Python C++ extensions that can be used in Maya.

1 comment on “Writing a Maya Python C++ ExtensionAdd yours →

  1. Hi, thanks a lot for the tutorial, extremely readable and informative (the trick of unload/recompile/reload being a true lifesaver).

    Do you think it’s possible to pass a Python API2.0 object to an extension function, directly recover the underlying C++ API object, perform operations, store the result in another C++ API object, wrap it with its Python wrapper and return it? Something like Shiboken’s wrapInstance/getCppPointer.

    A possible way for objects having proper constructors/getters (MMatrix, MPoints, …) is to use
    “PyObject_GetAttrString” and “PyObject_CallObject” to interact with the maya.api.OpenMaya layer but it becomes slightly more cumbersome when no explicit constructor/getter exists (MObject, MDagPath).

    I’d like to avoid this kind of manual conversions; it’s kinda doable in the old API by accessing to the SWIG proxy and messing with internal pointers (although not pretty).

    Thanks again.

Leave a Reply