This basic Maya Hello World C++ source code creates a plug-in which prints out "Hello World" in the Maya output window:
#include <maya/MSimple.h> #include <maya/MIOStream.h> DeclareSimpleCommand( helloWorld, "Autodesk", "2019"); MStatus helloWorld::doIt( const MArgList& ) { cout << "Hello World\n" << endl; return MS::kSuccess; }
To compile this code into a plug-in, create the helloWorld directory and save this code to a file name helloWorld.cpp in that directory.
Create a CMakeLists.txt file for this project and save it to the HelloWorld directory:
cmake_minimum_required(VERSION 2.8) set(PROJECT_NAME helloWorld) project(${PROJECT_NAME}) include($ENV{DEVKIT_LOCATION}/cmake/pluginEntry.cmake) set(SOURCE_FILES helloWorld.cpp ) set(LIBRARIES OpenMaya Foundation ) build_plugin()
Use CMake and the appropriate generator to build a project for your code:
Once you have built your project successfully, use CMake again to build your plug-in:
cmake --build build
You can now load your plug-in into Maya using the Plug-in Manager, which is accessed from Window > Settings/Preferences > Plug-in Manager from the Maya menu.
Once loaded, run helloWorld from the Maya command window:
The output will be written to the Maya output window:
You can also create a version which allows you to customize the greeting using arguments passed to the plug-in.
#include <maya/MSimple.h> #include <maya/MIOStream.h> DeclareSimpleCommand( helloWorld, "Autodesk", "2019"); MStatus helloWorld::doIt( const MArgList& args ) { cout << args.asString( 0 ).asChar() << " " << args.asString( 1 ).asChar() << endl; return MS::kSuccess; }
Before recompiling the plug-in, unload the plug-in from Maya using the unloadPlugin command.
You do not need to remake the plug-in project. You only need to recompile the plug-in using cmake --build build.
Reload the plug-in, and run it with two arguments:
Your greeting will be printed to the Maya output window: