Hello World Explained

The Hello World examples demonstrates several important components of plug-in development.

Detailed about the classes and functions listed here can be found in the C++ API reference.

MArgList

MArgList gathers arguments to a plug-in and stores them in a list. It provides similar functionality to the standard argc and argv of C and C++.

Both versions of Hello World use the MArgList assignment operator, const MArgList& args, to gather any arguments passed to the plug-in. However, only the second version of the plug-in uses the arguments passed to it:

cout << args.asString( 0 ).asChar() <<  " " << args.asString( 1 ).asChar() << endl;

The arguments passed to the plug-in are stored in the args list. The asString() function returns a list argument as an MString object. The asChar() function converts the MString to a C++ char *.

DeclareSimpleCommand

All plug-ins need to implement the initializePlugin(), uninitializePlugin(), and creator() functions.

The DeclareSimpleCommand() macro replaces initializePlugin(), uninitializePlugin(), and creator() in simple plug-ins so you do not have to implement these functions yourself.

DeclareSimpleCommand() takes three arguments: the plug-in class, the owner of the plug-in, and the version.

DeclareSimpleCommand( helloWorld, "Autodesk", "2020");

DeclareSimpleCommand() can only be used to create an undoable command. Because undoable commands cannot be undone, they should only query the scene. They should not modify the scene in any way.

Important:

If you create an undoable command that does modify the scene, it will break Maya's undo capability.

You need to include MSimple.h to use DeclareSimpleCommand().

doIt

In this simple example, doIt() performs the command's action, which is to write to the Maya output window.

In more complex command plug-ins, doIt() is used to parse arguments, set internal data, and do other housekeeping before it calls the redoIt() function. The redoIt() function then performs the command's actions.

As with most API functions, doIt() returns an MStatus object. The returned status can be used for error handling and error logging in more complex plug-ins. In this case, the plug-in always returns the success status code, MS:kSuccess