Efficient Maya development environment

How to setup your IDE so that clicking 'build' allows you to test and run your Maya plugin without extra steps or application restart.
To avoid copy/pasting plugin files it is best to tell Maya where to find the binary and scripts directly from your project folder. You can add the following environment variables:
Windows
MAYA_SHELF_PATH = C:\repo\trunk\plugin_name_maya\prefs\shelves/mayaxxxx MAYA_SCRIPT_PATH = C:\repo\trunk\plugin_name_maya\scripts;C:\repo\trunk\libraries\toolbox_maya\mel PYTHONPATH = C:\repo\trunk\plugin_name_maya\scripts MAYA_PLUG_IN_PATH = C:\repo\trunk\plugin_name_maya\lib\mayaxxxx\release;C:\repo\trunk\plugin_name_maya\lib\mayaxxxx\debug XBMLANGPATH = C:\repo\trunk\plugin_name_maya\prefs\icons
Linux
MAYA_SHELF_PATH = $PLUGIN_MAYA_PATH/prefs/shelves/mayaxxxx PLUGIN_MAYA_PATH = /home/user/repo/trunk/plugin_name_maya MAYA_SCRIPT_PATH = $PLUGIN_MAYA_PATH/scripts;C:\repo\trunk\libraries\toolbox_maya\mel PYTHONPATH = $MAYA_SCRIPT_PATH MAYA_PLUG_IN_PATH = $PLUGIN_MAYA_PATH/lib/mayaxxxx/release:$PLUGIN_MAYA_PATH/lib/mayaxxxx/debug XBMLANGPATH = $PLUGIN_MAYA_PATH/prefs/icons
Note 1 Instead of globally defining these variables in your OS,
you can instead define those in Maya.env
(usually located around `C:/Users/your_name/Documents/maya/2015-x64`)
Note 2 MAYA_SHELF_PATH
should always be defined first!
Once this setup is completed you should be able to load the plugin using one of the methods below:
Loading / Unloading your plugin
From Maya MEL command line
# loadPlugin plugin_name.mll # loadPlugin plugin_name_debug.mll // for the plugin in debug mode
From python cmds interface
cmds.loadPlugin("plugin.mll")
Alternatively if you haven't set PLUGIN_MAYA_PATH you can load plugins using an absolute path based on the location of your current python script:
cmds.loadPlugin(os.path.join(os.path.dirname(os.path.abspath(__file__)), "plugin.mll")
Through Maya GUI
Window -> Settings/Preferences -> Plug-in Manager
Remotely!
It is possible to execute maya commands remotely (i.e from the Operating system command line). This is really useful if you whish to automatically unload / build / reload the plugin without having to type or press anything in Maya! In other words it is possible to re-build the plugin with a single click, and test is immediatly directly in Maya. First you need to open a port in Maya with the Mel command:commandPort -n ":54321";
We recommend launching it automatically at each startup (through `userSetup.mel` in `maya_user_folder/scripts/userSetup.mel`) Then execute the python script in a flow that look like this:
py ./project_name/scripts/remote_plugin_unload.py make -j8 py ./project_name/scripts/remote_plugin_load_release.py
Example of python scripts.
Obviously you need to install python to execute those scripts (or use the interpreter installed with Maya)
Setup your IDE
It's worth noting it is usually pretty easy to setup your favorite IDE such as Qt creator, Eclipse etc. to execute those three steps when pushing the "build button"!
QtCreator
Go to your project settings clicking the icon on the left menu:

You can now add custom commands that are executed when you push the build button:

PyCharm
PyCharm has a plugin called MayaCharm that enables you to easily execute and debug your python code remotely while staying in PyCharm. As of today MayaCharm works only for PyCharm 2019.2.6 and below and has not yet been updated to support more recent versions. (untested: it should work with the community edition as well)
PyCharm setup: interpreter, auto-completion and doc with Maya
MayaCharm video tutorial
No comments