The Hello World examples demonstrates several important components of plug-in development.
In this simple example, doIt() parse arguments and writes to the Maya output window.
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++.
The asString() function returns a list argument as an MString object. The asChar() function converts the MString to a C++ char *.
MStatus helloWorld::doIt( const MArgList& args ) { cout << "Hello World " << args.asString( 0 ).asChar() << endl; return MS::kSuccess; }
In more complex command plug-ins, doIt() parses arguments, sets internal data, and does 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
See The doIt() and redoIt() functions for more information.
The command is instantiated using creator().
void* helloWorld::creator() { return new helloWorld; }
All plug-ins need to implement the initializePlugin() function. This function in turn calls registerCommand(). The plug-in will fail to load if initializePlugin() is not implemented.
Similarly, all plug-ins need to implement the uninitializePlugin() function. This function in turn calls deregisterCommand().
For more information, see Initializing and uninitializing plug-ins.
MStatus initializePlugin( MObject obj ) { MFnPlugin plugin( obj, "Autodesk", "1.0", "Any" ); plugin.registerCommand( "HelloWorld", helloWorld::creator ); return MS::kSuccess; } MStatus uninitializePlugin( MObject obj ) { MFnPlugin plugin( obj ); plugin.deregisterCommand( "HelloWorld" ); return MS::kSuccess; }