initializePlugin()
 
 
 

The initializePlugin() function can be defined as either a C or C++ function. If you do not define this function, the plug-in will not be loaded.

initializePlugin() contains the code to register any commands, tools, devices, and so on, defined by the plug-in with Maya. It is called only once—immediately after the plug-in is loaded.

For example, commands and tools are registered by instantiating an MFnPlugin function set to operate on the MObject passed in. This MObject contains Maya private information such as the name of the plug-in file and the directory it was loaded from. It is passed in to the MFnPlugin constructor, along with the vendor name which defaults to “Unknown” if not specified, the version number of the plug-in as a string which defaults to “1.0”, and the version of the API required for the plug-in to operate properly, which defaults to “Any”.

Once constructed, the MFnPlugin function set is used to register the contents of the plug-in file. In the example ( MFnPlugin), the MFnPlugin::registerCommand() is called to register the “hello” command, along with the creator (see Creator methods) for the command. Once done, the function returns a status code indicating whether or not it succeeded. After an unsuccessful initialization, the plug-in is unloaded automatically.