Maya API Visual Studio

Configuring Visual Studio for Maya API

This is a brief guide for configuring Visual Studio to build 32 and 64-bit Maya plugins.

In Visual Studio, create a new Win32 project. Specify DLL as the Application type and tick Empty project in Additional options.

Add a source file (i.e. main.cpp). This file can be empty for the time being. Its purpose right now is just to add the C/C++ configuration section to the project’s Property Pages.

Right-click on the project in the Solution Explorer and select Properties, bringing-up the Property Pages window. Change Configuration to All Configurations so that our changes affect both the debug and release builds.

Apply the following settings:

  • C/C++ > General > Additional Include Directories:
    • [path_to_maya]…\Autodesk\Maya[version]\include
  • C/C++ > Preprocessor > Preprocessor Definitions:
    • WIN32;NDEBUG;_WINDOWS;NT_PLUGIN;REQUIRE_IOSTREAM
  • C/C++ > Code Generation > Runtime Library:
    • Multi Threaded or Multi-threaded Debug DLL (/MDd)
  • Linker > General > Output File:
    • $(OutDir)\$(ProjectName).mll
  • Linker > General > Additional Library Directories:
    • [path_to_maya]…\Autodesk\Maya[version]\lib
  • Linker > Input > Additional Dependencies:
    • Foundation.lib;OpenMaya.lib;OpenMayaUI.lib;OpenMayaAnim.lib;OpenMayaFX.lib;OpenMayaRender.lib;Image.lib;opengl32.lib
  • Linker > Command Line > Additional Options:
    • /export:initializePlugin /export:uninitializePlugin

For developing a 64-bit project, a few extra settings are needed:

  • Configuration Manager > Active solution platform > New:
    • Type or select the new platform: x64
    • Copy settings from: Win32
    • Create new project platforms: True

Example projects can be found in: [path_to_maya]…\Autodesk\Maya[version]\devkit\plug-ins

I suggest navigating to this folder and examining these examples, starting with helloWorldCmd. Build helloWorldCmd.mll and then add it to the Plug-in Manager in Maya (Window > Settings/Preferences > Plug-in Manager > Browse). Invoking helloWorld in the MEL command-line should print “Hello World.”

For convenience’s sake, I have supplied Autodesk’s helloWorldCmd source code. It can be copy-and-pasted into the source file we created earlier:

 

For a faster setup, an example project can be repurposed into a template, or Maya’s setup wizard can be used. A lot of people (myself included) simply cannot get the setup wizard to work, which is why I mention it as an afterthought.

Visit Autodesk’s official Maya API documentation for more information: Autodesk Maya 2014 API Guide / Maya 2016 API introduction

If you have any problems, feel free to leave a comment below.