MAYA_SCRIPT_PATH
is the environment variable in question. The below docs apply equaly well to
MAYA_PLUG_IN_PATH
.
Additions are
usually stored and updated in the
Maya.env
file like:
MAYA_SCRIPT_PATH = c:\myScripts;
The
Maya.env
is usually stored per maya version:
C:\Documents and Settings\<userName>\My Documents\maya\<version>\Maya.env
The
Maya.env
file is parsed when Maya launches, so any modifications to it require Maya to be restarted to be seen.
Two examples below to add a new path to the current environment variable,
after Maya has launched:
Python notes:
The
maya.cmds
package doesn't include mel's
getenv
and
putenv
, however, Python's
os
module does contain similar functions (
os.getenv
,
os.putenv
). However, based on the below example,
os.putenv
doesn't actually do anything: It fails to update the path. However, by modifying the dictionary
os.environ
directly, we are able to make the change.
import os
newPath = r"c:\some\path\to\add"
# Do this so we have a common base to compare against:
comparePath = newPath.lower().replace("\\", '/')
notInPath = True
sysPath = os.getenv('MAYA_PLUG_IN_PATH')
paths = sysPath.split(';')
for path in paths:
# Make the path we're comparing against the same format
# as the one we're trying to add:
compare = path.lower().replace("\\", '/').replace("//", '/')
if comparePath == compare:
notInPath = False
break
if notInPath:
# Update our plugin path:
newPath = '%s;%s'%(sysPath, newPath.replace("\\", "/"))
#os.putenv('MAYA_PLUG_IN_PATH', newPath) # This doesn't work, interesting...
os.environ['MAYA_PLUG_IN_PATH'] = newPath
Mel notes:
// Define our new path to add:
string $newPath = "c:/temp";
// Get our path, and split into list:
string $msp = `getenv "MAYA_SCRIPT_PATH"`;
string $pathList[];
tokenize $msp ";" $pathList;
// For comparison purposes, make all slashes forward, and add
// a slash to the end
$newPath = fromNativePath($newPath);
if(`match "/$" $newPath` != "/")
$newPath = ($newPath + "/");
int $found = 0;
// Loop through all the paths, seeing if our path already exists:
for($i=0;$i<size($pathList);$i++)
{
// Same comparison check from above:
string $compare = fromNativePath($pathList[$i]);
if(`match "/$" $compare` != "/")
$compare = ($compare + "/");
if(tolower($newPath) == tolower($compare))
{
$found = 1;
break;
}
}
// If no new path was found, add:
if(!$found)
{
// The *whole* path needs to be re-added:
// putenv seems to replace, not append.
$pathList[size($pathList)] = $newPath;
string $fullPath = stringArrayToString($pathList, ";");
putenv "MAYA_SCRIPT_PATH" $fullPath;
print ("Added to MAYA_SCRIPT_PATH '" + $newPath + "'\n");
}
else
print ("path '" + $newPath + "' is already in the MAYA_SCRIPT_PATH\n");
To just query what dirs are currently in the path:
string $msp = `getenv "MAYA_SCRIPT_PATH"`;
string $pathList[];
tokenize $msp ";" $pathList;
print $pathList;