How-To: Maya userSetup sharing

For those that do not know; userSetup files allow you to run scripts automatically on Maya start up. Many scripts use this. There is a problem with userSetup files though.. just like Highlander there can be only ONE!

Well two actually: userSetup.mel and userSetup.py

Usually this is not a problem. If you install two scripts that need userSetup files then you simply merge them together manually. Things become more complicated distributing scripts across a large team.

Question: How do we share a userSetup file and still allow artists to install their own scripts locally?

And why do we want to do that? Because this way we can deploy scripts and load them on Maya start up without having to update every artists userSetup file across a studio. We can also execute snippets of code that:

  • Pre-load plugins
  • Initialize default animation/scene settings
  • Utilize shared User Commands (follow up post on that later this week).

Solution: The concept I came up with is relatively simple. Rename the userSetup file on the artists machine as localSetup.mel and localSetup.py! Then add some code to our master userSetup file to look for and execute the contents of those files.

How To:

In userSetup.mel add:

////////////////////////////////////////////////
// DETECT AND LOAD LOCAL SETUP ON USERS MACHINE
////////////////////////////////////////////////
string $env = `getenv MAYA_SCRIPT_PATH`;
string $pathList[];
tokenize $env ";" $pathList;

// check if localSetup exists in any of Maya's script paths
int $f=0;
for ($path in $pathList) {
	if (`filetest -f ($path + "/localSetup.mel")`) {
		$f = 1;
		break;
	}
}

// source the localSetup file if it exists
if ($f != 0) {
	print ("loading localSetup.mel \n");
	eval "source localSetup.mel";
} else {
	print ("localSetup.mel not found. Skipping. \n");
}

And for userSetup.py add:

# DETECT AND LOAD LOCALSETUP ON USERS MACHINE
try:
	from localSetup import *
except ImportError:
	print "localSetup.py not found. Skipping."

That’s it! Now all an artist has to do is rename their own userSetup files to localSetup and they can continue to install scripts locally that need to run on Maya startup (such as Maya’s bonus tools). You could theoretically use this technique to load any number of userSetup files across different departments (animSetup, charSetup, envSetup, etc).

Read More