Distributing Maya plugins

Here I discuss various ways you can ship a Maya plugin to end users. Ultimately the methods I present below can be automated and wrapped with scripts or installers (.msi etc.) You can see my  Git repository ] to get a template project that demonstrate how to generate a windows installer for Maya plugin with CMake and CPack.

A plugin usually contains:

You need to gather all those files and tell Maya where to find them. To this end you will need to define the following Maya environment variables:

MAYA_SHELF_PATH=C:\installation_folder\prefs\shelves // <- Must be defined first
PYTHONPATH=C:\installation_folder\scripts 
MAYA_SCRIPT_PATH=C:\installation_folder\scripts 
MAYA_PLUG_IN_PATH=C:\installation_folder\plug-ins 
XBMLANGPATH=C:\installation_folder\prefs\icons 

Defining those variables can be done as follows:

Each method as its pros and cons which I will detail below. Personally my preference goes to the Application Plugin method which I find the most robust. This is also the official method to provide plugins through the autodesk app store (see also developer guidelines). Finally this is the method I use in my template project demonstrating how to ship a Maya plugin with CMake/CPack.

Using system environment variable

Directly edit the user's system environment variable with a bat script to add the needed variables (MAYA_SHELF_PATH etc.)

Pros

Cons

I don't recommend at all...

Using Maya.env

You directly add a file Maya.env in  C:\Users\name\Documents\maya\version\ . Pros and cons are almost identical to the above method.

Pros

Cons

If you're testing out your plugin on your local machine it's a good solution, but I don't recommend for shipping.

Using a custom shortcut

Start Maya with a special script that loads the correct environment variables! You can also have a shortcut linking to %COMSPEC% /C start /d Contents\ launch.bat 2018 in order to launch your script. 

Pros

Cons


Using the module file

Just add a .mod file in the user directory C:\Users\name\Documents\maya\version\modules\. See the Maya documentation to understand this file format. The shelves won't load you will need to include a userSetup.py in your script folder (PYTHONPATH)

 Pros

Cons

Using Application plugin

Almost the same as the module version but it is the official way to distribute plugins on the Autodesk app store. Plus you can specify a custom mel script to be launched at startup.

Add a PackageContents.xml file in:

The MEL script specified in the xml file your-plugin-name_load.mel will be automatically executed at startup. You can see many other examples of PackageContents.xml just looking at the installation files of some free plugins on the Autodesk App store.

 Pros

Cons

This my favorite option.

References

Application plugin
Modules (1)
Modules (2)

One comment

Is there a good way to automatically run python code as Maya starts with the Custom Shortcut approach? As far as I can tell it won’t run code in a userSetup.py file which resides in the PYTHONPATH location defined via the shortcut?

Thanks
————————————————
Rod: I’ll have to test it but I don’t see why the shortcut method would not launch userSetup.py. In case it doesn’t you can always tell maya to execute mel commands when executing: maya.exe -command “some mel commands”. If you incorporate this method in the shortcut method it should work.

KG - 25/09/2020 -- 11:59
(optional field, I won't disclose or spam but it's necessary to notify you if I respond to your comment)
All html tags except <b> and <i> will be removed from your comment. You can make links by just typing the url or mail-address.
Anti-spam question: