Writing a simple plug-in
 
 
 

The following provides information on how to write a simple plug-in called Hello World.

Writing your first plug-in

When learning a new computer language, the first program you are likely to see is a “Hello World” program. Following this tradition, the first plug-in we create is a “Hello World” plug-in, which simply outputs “Hello World” to the window from which Maya was launched.

#include <maya/MSimple.h>
#include <maya/MIOStream.h>
DeclareSimpleCommand( helloWorld, "Autodesk", "2010");
MStatus helloWorld::doIt( const MArgList& )
{
 cout << “Hello World\n” << endl;
 return MS::kSuccess;
}

Linux 64-bit:

If this is put into a file called helloWorld.cpp it can be compiled with:

g++412 -c -I. -I.. -I/usr/autodesk/maya2010-x64/include -I/usr/X11R6/include -m64 -O3 -pthread -pipe -D_BOOL -DLINUX_64 -DREQUIRE_IOSTREAM -fPIC -mtune=pentium4 -Wno-deprecated -fno-gnu-keywords helloCmd.cpp
g++412 -shared -m64 -O3 -pthread -pipe -D_BOOL -DLINUX -DREQUIRE_IOSTREAM -mtune=pentium4 -Wno-deprecated -fno-gnu-keywords -Wl,-Bsymbolic -shared -o helloCmd.so helloCmd.o -L/usr/autodesk/maya2010-x64/lib -lOpenMaya -lFoundation

Windows and Mac OS X:

If this is put into a file called helloWorld.cpp, it can be compiled by following the platform-specific instructions in Creating your own plug-in build file in Introduction to building plug-ins and applications.

Once the file has compiled, you can load it into Maya (see Loading a Plug-in). Type “helloWorld” into the command window (press Enter to invoke the command), and “Hello World” displays in the output window.