Maya API.. I almost threw up when I saw some of source code of plugins written in C++. I always wonder how Maya works in the background so I have been eager to learn it to extend my knowledge in Maya.
This is a quick introduction on how to get a compiler set up for compiling on Windows 32bit platform(s). Compiling on Windows 64bit requires more setups and additional software to be installed, and it is not covered in this section.
Firstly, you need to install "
Microsoft visual express C++", one I'm using is version 2010. You can use earlier versions of VC++ to compile your project files to a plugin.
Once the VC++ is installed, you are ready to start compiling project files to plugins!
I was told by many experts that DevKit is a good starting point to learn how to compile plugin(s) and learn API by looking at the source code.
The DevKit area can be found here - C:\Program Files\Autodesk\Maya2011\devkit\
To find example project files, go to C:\Program Files\Autodesk\Maya2011\devkit\plug-ins. In the directory you find a lot of files with extensions .cpp, .h,.vcproj..
Files with .vcproj file extension are files that you can open with VC++ program which you have installed. Double-clicking on the file should open in VC++.
Find a file "helloCmd.vcxproj" and open this in VC++. In VC++, a conversion wizard window may pop up. Click on 'next', and select 'create a backup before conversion' then hit 'next'. It should say
the conversion has finished succesfully with some warnings. We can ignore the warnings here. Close the conversion window.
We have just opened up the project file, and the project is ready to be compiled. Hit F7 key to compile(build solution). After compiling has finished,we should find a compiled plugin called "helloCmd.mll" in the same directory.
This .mll file can be loaded to Maya via the plug-in manager.
Jeremy has written a good tutorial how to compile "Simple fluid emitter".
| read |
So you are starting to get the hang of compiling samples from devkit? It's time to start writing your own..
A lot of experienced API experts stress to say not to use the plugin wizard for VC++, and instead manually create projects from scratch.
Anyhow this is a quick introduction on how to set up the Maya plugin wizard for VC++ 2010 express on Windows 7(64bit platform).
What I'm using for this tutorial:
Windows 7 (64bit)
Maya 2011 (32bit)
VC++ 2010 Express (32bit)
Maya plugin wizard 2.0 - i'm using one from creativecrash
Download the wizard above then read the readme file in the archive. But you need to do the followings to make it work.
in MayaPlugInWizard.vsz, change Wizard=VsWizard.VsWizardEngine.9.0 to Wizard=VsWizard.VsWizardEngine.10.0
Copy these 3 files (MayaPluginWizard.vsdir,MayaPluginWizard.vsz,MayaPluginWizard.ico) to C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\Express\VCProjects
Copy /MayaPlugInWizard/ folder to C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\VCWizards (NOT /Express/ directory!)

Problems you may encounter:
Error [File name or class name not found during Automation operation] - open this file MayaPluginWizard\Scripts\1033\default.js then change '.vcproj' to '.vcxproj'
Error [fatal error C1083: Cannot open include file: 'maya/MSimple': No such file or directory] - make sure you add the Maya directories into Visual C++. From the main menu -> Tools -> Options -> Projects -> VC++ Directories. add a line for both the include and lib directories of maya
Here is the settings in the property that a simple wizard creates by default:
C/C++ > General > Additional Include Directories: C:\Program Files\Autodesk\Maya2011\include;
C/C++ > Preprocessor > Preprocessor Definitions: WIN32;_DEBUG;_WINDOWS;_AFXDLL;_MBCS;NT_PLUGIN;REQUIRE_IOSTREAM;Bits64_;%(PreprocessorDefinitions)
Linker > General > Output File: $(ConfigurationName)\helloTestCmd.mll
Linker > General > Additional Library Directories: C:\Program Files\Autodesk\Maya2011\lib;
Linker > Input > Additional Dependencies:
Foundation.lib;OpenMaya.lib;%(AdditionalDependencies)
Linker > Command Line:
/OUT:"Debug_2011\tstCmd.mll" /NOLOGO /LIBPATH:"C:\Program Files\Autodesk\Maya2011\lib" /DLL "Foundation.lib" "OpenMaya.lib" "kernel32.lib" "user32.lib" "gdi32.lib" "winspool.lib" "comdlg32.lib" "advapi32.lib" "shell32.lib" "ole32.lib" "oleaut32.lib" "uuid.lib" "odbc32.lib" "odbccp32.lib" /MANIFEST /ManifestFile:"helloTest.dll.intermediate.manifest" /ALLOWISOLATION /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /PDB:"Debug_2011/tstCmd.pdb" /PGD:"C:\Users\userName\documents\visual studio 2010\Projects\tstCmd\Debug_2011tstCmd.pgd" /TLBID:1 /DYNAMICBASE /NXCOMPAT /IMPLIB:"Debug_2011/tstCmd.lib" /MACHINE:X86 /ERRORREPORT:QUEUE
/subsystem:windows /dll /incremental:yes /debug /export:initializePlugin /export:uninitializePlugin
Notice that some directories are pointing to C:\Program Files\Autodesk\Maya2011\ in the settings above, yet the compiler seemed to have compiled a simple project to a plugin without any problem.. but it is wrong as my Maya resides in C:\Program Files (x86)\Autodesk\Maya2011\. I would suggest setting them to the correct dirs.
Here is a simple guide to setting up a project without help of using Maya Plugin Wizard..
Requirements for this project:
Windows 7 (64bit)
Maya 2011 (32bit)
VC++ 2010 Express (32bit)
Create a new project > Win32 Project -> choose .DLL
In Project Properties, please make sure you configure your project like below:
Debugging > Command: C:\Program Files (x86)\Autodesk\Maya2011\bin\maya.exe
VC++ Directories > Include Directories: C:\Program Files (x86)\Autodesk\Maya2011\include;
VC++ Directories > Library Directories: C:\Program Files (x86)\Autodesk\Maya2011lib;
C/C++ > General > Additional Include Directories: C:\Program Files (x86)\Autodesk\Maya2011\include;
C/C++ > Preprocessor > Preprocessor Definitions: WIN32;_DEBUG;_WINDOWS;NT_PLUGIN;REQUIRE_IOSTREAM;
Linker > General > Output File: $(OutDir)\$(ProjectName).mll
Linker > General > Additional Library Directories: C:\Program Files (x86)\Autodesk\Maya2011lib;
Linker > Input > Additional Dependencies: (you may not add all the libs depending on your project.)
Foundation.lib OpenMaya.lib OpenMayaUI.lib OpenMayaAnim.lib OpenMayaFX.lib OpenMayaRender.lib Image.lib opengl32.lib
Linker > Command Line: add the followings
/export:initializePlugin /export:uninitializePlugin
Resources:
hajime nakamura's API - has a section for problem solving. It's a bit old but still a nice reference.
This is a good place to start. Check out the Maya API reference webpage at Autodesk.
| read |
Quick API tutorial by Koichi. It's old but a good reference.
| read |
It would have been good if I could write more about API in this page but if you would like to learn more about API please join me here. -
Maya API C++ mailing list