Here’s a quick and dirty way to get a C++ plugin compiled for Maya in just a handful of steps. This tutorial will utilize existing Maya plugin example projects. We will insert our code into these projects to take advantage of the settings that are already there, reducing the number of steps it will take you to get your plugin up and running. Further, barring incompatible source code due to API changes, etc, this method will produce a plugin compatible with your current Maya install.
Software Requirements: Autodesk Maya, Visual Studio
Notes: If your source code was written for a vastly different version from your current Maya install, your plugin may not function properly. Further, your plugin may reference files outside of Maya’s default libraries. If this is the case, you will need to track those files down and include them in your project. We will cover including headers and libraries.
Step 1: Locate the source code that you want to compile.
For this walk through, I will be using Katrin Schmid’s code for a smooth deformer located here. The smooth deformer contains three files: main.cpp, smDef.h, and smDefNode.cpp. If you would like to compile your own plugin, gather your source files now.
Step 2: Locate an example plugin
Navigate to your Maya install directory and then to “devkit\plugins”. For me, the full path is “C:\Program Files\Autodesk\Maya2013.5\devkit\plug-ins”. This is where we will grab an example plugin to inject our code. The Circle Node plugin has worked well for me in the past, but feel free to use any plugin that suits your needs. Copy the circleNode folder and rename it so that we don’t mess with the original code. I’ll rename mine to smoothDeformer.
Note: One of the advantages of this approach is that if you source your plugin example, the includes, and libraries (covered later) from a given Maya install directory, your plugin will automatically be compatible with that version of Maya.
Step 3: Open the code, set include and lib directories
Inside of your new folder you should find circleNode.sln. Open this file with Visual Studio (if you used a different example plugin, open the .sln file). If the Update VC++ Compiler and Libraries window pops up, click Update. In the Solution Explorer toolbar on the right side of the window, click circleNode.cpp to open it. You should be seeing the following with some of the #include lines underlined in red.
This means that Visual Studio can’t find those include files. Before fixing this, we just need to rename our project so that the build target name is correct. Right click on the circleNode project, select rename, and give your project a new name.
To remedy the missing includes we need to add a path to the Include Directories. Again, right click on the circleNode project but this time select properties to open our Property Pages window. Under Configuration Properties select VC++ Directories. Then, in the box to the right select Include Directories, click the drop down arrow and select <edit…>.
In the window that pops up, paste the path to your Maya include directory. For me, this is “C:\Program Files\Autodesk\Maya2013.5\include”. Click OK. You should now see that path in the Include Directories field of the Property Pages window. Next, we need to add the library directory. Under Configuration Properties > Linker > General, select Additional Library Dependencies and add a new path field as before, but this time to Maya’s lib directory. For me, this is “C:\Program Files\Autodesk\Maya2013.5\lib” Click Apply in the Properties Pages window. All of those ugly red lines should disappear!
Step 4: Replace the code
We simply need to delete the original code and add our new code. Right click circleNode.cpp and remove it from the project. Do this for any additional code files (.cpp and .h) that your example plugin might have. You can even remove any original MEL files. For the smooth deformer, we need to add main.cpp, smDef.h and smDefNode.cpp. Right click on the circleNode project (as before in Figure 2) but this time select Add > Existing Item. Locate any source files that you wish to add (in my case, main.cpp, smDef.h and smDefNode.cpp), select them, and click Add. Those files should now be added to your project.
Lastly, for some plugins we need to tell the linker to add OpenMaya. Paste #pragma comment(lib,“OpenMayaAnim.lib”) main.cpp, just under the #include statements. It doesn’t seem to actually matter which file you add this to, but I think that this is a sensible place to put it.
Step 5: Compile and load
Switch your solution to release configuration by selecting Release from the drop down on the top toolbar.
Finally, we are ready to compile! From the top menu, select Build > Build Solution. Hopefully your plugin compiles successfully. This will dump an .mll file into your project release (or debug) directory. The easiest way to get there is to right click on your project in the Solution Explorer (as in Fig. 2) and click Open Folder in File Explorer. Your compiled plugin will be located within the x64\release directory. If you compiled in debug, look in the debug folder. Likewise, if you compiled for x86, look in the x86 folder.
That’s it! You can now do as you please with the MLL file. To load in it Maya, select Window > Settings/Preferences > Plug-in Managerin your Maya session. Then click Browse and locate your MLL file to load the plugin!