- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Examples

- Class List
- Class Hierarchy
- Class Members

Public Member Functions | Static Public Member Functions

# MLibrary Class Reference

This reference page is linked to from the following overview topics: Extension for Autodesk Maya 2013, Example stand-alone application descriptions, Appendix C: Frequently asked questions.

Search for all occurrences

## Detailed Description

Set up Maya to run in library mode. (OpenMaya)

Initialize and cleanup routines for Maya running in library mode.

When creating a "library mode" Maya application, this class must be used in the program's main routine to initialize Maya, and later to cleanUp allocated Maya state. A typical usage would be:

        main(int argc, char **argv)
        {
            MStatus status;
            status = MLibrary::initialize (argv[0], true);
            if ( !status ) {
                status.perror("MLibrary::initialize");
                return (1);
            }

            // Maya API code goes here

            MLibrary::cleanup();
            return (0);
        }

If the call to cleanup is omitted, you will get errors when the program exits as the static destructors in the Maya libraries are run.

`#include <MLibrary.h>`

List of all members.

## Public Member Functions
| MLibrary ()
| The default class constructor.
virtual | ~MLibrary ()
| The class destructor.
## Static Public Member Functions
static MStatus | initialize (const char *applicationName, bool useBatchLicense=false)
| Initialize the Maya library.
static MStatus | initialize (bool wantScriptOutput, const char *applicationName, bool useBatchLicense=false)
| Initialize the Maya library.
static void | cleanup (int exitStatus=0, bool exitWhenDone=true)
| Undo the initialization performed by the initialize method, cleanup allocated Maya structures in an orderly fashion and terminate the application.

## Member Function Documentation

MStatus initialize | ( | const char * | applicationName,
|  | bool | useBatchLicense = `false`
| ) |  | `[static]`

Search for all occurrences

Initialize the Maya library.

This method must be called before any Maya functionsets are used. It is acceptable to instantiate Maya fundamental types before calling this, but attempts to do anything else cause unpredictable results. When writing a Maya library mode application, a call to this method should be the first line of main.

Parameters:

  [in] | applicationName | The name of this application. Typically argv[0] from the application's main() function is passed in this parameter.
  [in] | useBatchLicense | Determines whether a full or batch license of Maya is required to run the application. Most of Maya's features are accessible to library applications with just a batch license. Note that this setting does not affect the result of MGlobal::mayaState(), which always returns kLibraryApp for library applications, nor does it it affect the result of the about -batch command, which always returns true for library applications.

Returns:
  - MS::kSuccess Maya was initialized successfully.
  - MS::kLicenseFailure The requested license could not be obtained.
  - MS::kFailure Maya failed to initialize.

MStatus initialize | ( | bool | wantScriptOutput,
|  | const char * | applicationName,
|  | bool | useBatchLicense = `false`
| ) |  | `[static]`

Search for all occurrences

Initialize the Maya library.

This method must be called before any Maya functionsets are used. It is acceptable to instantiate Maya fundamental types before calling this, but attempts to do anything else cause unpredictable results. When writing a Maya library mode application, a call to this method should be the first line of main.

Parameters:

  [in] | wantScriptOutput | Set to true if you wish script output to be generated. For example if you are using the the MGlobal::displayInfo() method.
  [in] | applicationName | The name of this application. Typically argv[0] from the application's main() function is passed in this parameter.
  [in] | useBatchLicense | Determines whether a full or batch license of Maya is required to run the application. Most of Maya's features are accessible to library applications with just a batch license. Note that this setting does not affect the result of MGlobal::mayaState(), which always returns kLibraryApp for library applications, nor does it it affect the result of the about -batch command, which always returns true for library applications.

Returns:
  - MS::kSuccess Maya was initialized successfully.
  - MS::kLicenseFailure The requested license could not be obtained.
  - MS::kFailure Maya failed to initialize.

void cleanup | ( | int | exitStatus = `0`,
|  | bool | exitWhenDone = `true`
| ) |  | `[static]`

Search for all occurrences

Undo the initialization performed by the initialize method, cleanup allocated Maya structures in an orderly fashion and terminate the application.

Note: It is important that when a Library mode process terminates it calls this method before doing so. Failure to do so could result in the leaking of licenses and errors from Maya's static destructors.

If the exitWhenDone parameter is true, which is the default, this method will terminate the process, using the supplied exitCode, and control will NOT be returned to the caller.

If the Library app was launched from another process as a separate thread or a child process, this can result in the parent process terminating as well. To avoid that, set exitWhenDone to false, which will prevent the current process from being terminated and will return control to the caller. However, in that case, Library mode must not be re-entered within the same process as Maya will be in an undetermined state and its behavour would be unpredictable.

Parameters:

  [in] | exitStatus | The exit code the application will return.
  [in] | exitWhenDone | If true, terminate the process. If false, return control to the caller without terminating the process.

MLibrary MLibrary MLibrary MLibrary MLibrary MLibrary MLibrary MLibrary MLibrary MLibrary
MLibrary MLibrary MLibrary MLibrary MLibrary MLibrary MLibrary MLibrary MLibrary MLibrary