Maya C++ API

First you must have Maya and be pretty good at using Maya.
I'm not, so don't worry too much.

Why do we need it? To make Maya do even more amazing things.

We learned previously that an API is just a set of functions.

The Maya C++ API is also a set of extra functions as you may guess, but this time we use them from Maya after compiling them in the C++ environment. We compile our program in C++ and use it in Maya. How do we use it in Maya? We load it. How do we do that? From Maya we choose Windows, Settings, Preferences , go searching for our compiled code and click Load. We can then issue a command from the Maya command line to run our C++ "Add-In".

Lets start again. How do we produce our compiled code? C++ must be geared up to produce this Maya compatible code. To do that we need to have run a wizard. In my case, using Maya 6.0 and VS.NET 2005 I managed to locate a link to an appropriate wizard at

Not all Maya versions are compatible with all versions of C++. After spending many hours trying to get Maya 6.0 to work with Visual Studio version 6.0, I happened to read somewhere that it just was not possible if I remember rightly!

In fact let me warn you about the Maya C++ API. The learning curve is about the same for C++ itself but even worse since comprehensible documentation out there is very lacking. I hear that a chap named B Ewert has a very useful site, but unfortunately it seems to be down. So you're on your own. Gould's books are very good but need a lot of decyphering. Many, many concepts are bundled together into one example at times. You need dedication and a lot of trial and error. The main problem with the Help with the Maya classes and functions - which by the way is from Maya - not C++ - even though you use them from C++ - is the lack of coding examples. Sometimes the simplest example can be very illuminating. Come back MicroSoft all is forgiven.

After running the wizard, in the Visual C++ IDE, you will then notice the Maya PlugInWizard in your New Project window.

You will also need to sort out the location of your include and library files from the IDE.

At last you can write some code. Here is the traditional starting program which writes Hello World (makes me feel part of the family) to Maya's Output Window.

It doesn't do anything to your Maya scene which really is what we are ultimately trying to do, but at least its a lot easier to understand.

Build (compile) it. The compiled file is called myCmd.mll.

#include <MSimple.h>
#include <iostream>
using namespace std ;
DeclareSimpleCommand( myCmd, "", "7.0") ;
MStatus myCmd::doIt( const MArgList& args )
MStatus stat ;
cout << "Hello World!\n" << endl ;
return MS::kSuccess;

We must note where it was saved.

Now from Maya, we must load the compiled Plug-In (or Add-In) as follows:

From The Plug-in Manager dialog box (see below) in Maya, Browse to the .mll as shown immediatelybelow.:

From the Plugin manager browse to:

Note that myCmd.mll is loaded.

Close this dialog box.

From the command line (or the Script Editor) :


When a new project is started, the wizard produces some skeleton code. This was not used in our Hello World example, but could be – see page 291 Gould Vol1.

Unfortunately, if we need to edit our Add-In in C++ (and of course re-compile it) , we must unload it each time in Maya! and then reload it!. (see note page 6 of MayaAPISetup.doc). Accordingly, it is expedient to write MEL script to do this and place a button on the shelf. See pages 9, 10 of MayaAPISetup.doc notes. (Ed-not done yet)