How to create C++ Plugin for Maya
GOAL
To set up the environment for C++ Maya plugin. To build sample plug-in and execute it.
Environment
Maya 2018
Maya 2018 Update 6 win64 DevKit
Windows10 with environment for C++ compile
Microsoft Visual C++ 2017 ver15.8.4
Method
Get Maya DevKit
Access Maya Developer Center. And scroll down to click “Maya <version> Update 6 win64 DevKit”. Then unzip the file.
Setting up the build environment
Refer to Autodesk Maya Document “Setting up your build environment“.
Add the 3 directories, \devkit , \mkspecs in devkitBase into Maya installation directory (e.g. C:\Program Files\Autodesk\Maya2018).
* To compile custom plug-ins, you can also find the C++ API header files(\include\maya ) and libraries(\lib).
Build enclosed plug-ins in Visual Studio
Open devkit/plug-ins folder( either maya installation folder or newly created folder where plug-in folder is copied and put would be fine). I create a folder named “maya_cpp_plugin” and copy plug-in files to the new folder.
Find “Hello World Cmd” and open it.

Add folder “include” into the list of include directories for Visual Studio. Right Click the name of project name and open Properties.

Then, add ” C:\Program Files \ Autodesk\Maya2018\include” into the Additional Include Directories.

Add ” C:\Program Files\Autodesk\Maya2018\lib” into Additional Library Directories.

Open solution file *.sln, then Visual Studio will start up. Click Build > Build Solution.

The output files are in the directory maya_cpp_plugin\helloWorldCmd\x64\Release(or Debug). “helloWorldCmd.mll” is the main plugin file.
Plug-in installation
Refer to Autodesk Maya Document “Installing a Maya plug-in“.
Add plugin helloWorldCmd.mll to the plug-in directory defined as MAYA_PLUG_IN_PATH in <username>\Documents\maya\<version>\Maya.env file. If Maya.env doesn’t exist, create it according to “Setting environment variables using Maya.env“.
Start Maya and open Plug-in Manager.

Click a check mark next to helloWorldCmd.mll

Execute the Plug-in with command
Open Script Editor and execute the Command “helloWorld”.


The message “helloWorld” is displayed on the console, upper side of the Script Editor.