Maya-Environment-Setup

Autodesk Maya Environment Setup

Overview

Maya environment setup for you and your team. Deliver your tools and integrate scripts easily. Automate the setup in a team setting and add callbacks to manage scene preferences and source control.

What is the Maya environment?

Maya has specific environment variables that defines where it looks for scripts and resources.
Add your own paths to these variables so that we can store our scripts and resources wherever we want.

Maya environment scripts

The most common way to modify the Maya environment is through three script files in the preference directory, namely Maya.env, userSetup.mel and userSetup.py. Maya evaluates these scripts, in the order mentioned, during boot and thus presents an opportunity to inject paths for our tool environment.

“What if I want to organize my add ons so I can easily turn things on and off? ”
“As a tech artist, I don’t want to deal with pre existing configuration information when I modify the end user’s Maya environment.”

Luckily, there is an alternative to the three files mentioned above, namely Maya modules.

Maya modules

A Maya module is a .mod file that we create to modify the Maya environment. First, look in Maya’s install directory/modules .
– Windows example path: “C:\Program Files\Autodesk\Maya2018\modules”. 

Fbx, Substance, Xgen and Houdini Engine all use this method to bootstrap their environment in Maya.
We will create our own .mod file in a modules directory in the Maya preferences directory.

In the module file, you specify a path to a “Maya site” folder. To the right you see the structure of the site folder we will use.

The sub folder names “icons”, “shelves” and “scripts” are automatically added to the Maya environment during startup.

Maya-environment-Module-Site

Maya Module Site

Manually implementing a module

First, go to the Maya user preference directory and create a folder called “modules”.

Put the directory in the root, as opposed to into a Maya version folder, which causes all modules to be loaded for all versions of Maya.

If you need specific version control, you can also create a modules directory inside of any given Maya version preference folder.

Maya-Environment-Preferences

Maya Preferences

Next, create a .mod file inside the modules folder you just created (I name mine LCG.mod). Put the content below in the .mod file, and change the paths how you see fit.

The first line tells Maya that we want to add (+) this module. We give it a name and a version as well as the path to our “Maya site”. Maya adds the “icons” and “scripts” folders automatically during boot. To get shelves to auto load in Maya, we add the path to the MAYA_SHELF_PATH environment variable.

Verifying the Maya environment

Start up Maya, copy and paste the code below into the script editor and run it to verify that the paths have been added to your environment.

Thanks to Maya modules, we append to the Maya environment without dealing with Maya.env, userSetup.mel or userSetup.py. Feel free to create as many modules as you want. One per project/team/game/freelance job – the sky is the limit.

“I want to automate the creation of this setup for my team(s)? ”
“I want the Maya site and framework to be able to be stored in any random location for each member of the team.

Set this up is via a Maya Python plug in. It is flexible, easy to maintain and simple to implement.

Automating the module install

A Maya Python plug in is, is a .py file that we load from the Maya plug in manager. Look below how easy it is to implement.

Copy and paste the code into a .py file and load it from the Maya plug in manager, you will get the print statement when you check the load checkbox in the Maya plug in manager.

Introduce the modification to the Maya environment in the load function and do whatever house cleaning necessary when the plug in is unloaded in the teardown function.

I detect where the plug in loads from and set up the Maya environment from there…
Let’s dive into the load function.

The load function

The plug in will auto-load, so the following gets added or created every time Maya is started.

  • Plug in paths to the Maya environment
  • Python root path to sys.path
  • .mod file in user local preferences
  • Before scene save callback – great for source control
  • After open scene callback – manage scene configuration
  • New scene callback – manage scene configuration
  • Override incrementalSaveScene (due to AD bug)

Below is the basic structure of our framework. If you geek out on how to structure your framework and dynamically resolve certain Python modules within your own framework, check this post out.

Maya-Environment-Framework-Structure

Let’s step through the load function. Read the comments for each section to follow along what is happening. I marked the variables that we are defining in code below on the overview image of the framework structure above.

Tip
Since some of the code lines below are fairly long, use the “Open code in new window” button on the far right to maximize while still being able to see the framework structure.

The teardown function

Compared to the load function, the teardown function is pretty simple.
We get the following things removed in our teardown:

  • Python root path to sys.path
  • Before scene save callback
  • After open scene callback
  • New scene callback
  • Re-source the original incrementalSaveScene

Conclusion

I hope this article will be useful. If it is, please drop me a comment below. Also feel free to share your own experience and how you go about dealing with the Maya environment setup.

Cheers,


About the Author

Christian Akesson

Facebook Twitter Google+

Technical Artist at Amazon Game Studios. Maya user since beta 1 in 1999.