PDA

View Full Version : Setting MAYA_SHELF_PATH in userSetup.py


gordrob
01-19-2011, 05:26 PM
I am trying to use userSetup.py to set various Maya environment variables so Maya will load some custom shelves from a non-standard folder. These shelves rely on some scripts, icons and plug-ins that also reside in a non-standard folder, so I am trying to set several environment variables in userSetup.py. The contents of userSetup.py are below.


# Python imports
import os.path

# Maya imports
import maya.mel as mel

perforceDepot = r"C:\working\depot"

# add appropriate common tools paths to the maya environment variables
environmentVariableNamesToPathsToAdd = {
"MAYA_SHELF_PATH" : r"Tools\Maya\Shelves\2009",
"MAYA_SCRIPT_PATH" : r"Tools\Maya\MelScripts",
"XBMLANGPATH" : r"Tools\Maya\Icons",
"MAYA_PLUG_IN_PATH" : r"Tools\Maya\Plugins\2009",
"PYTHONPATH" : r"Tools\Maya\Python",
}

for name, path in environmentVariableNamesToPathsToAdd.items():
print name
originalPath = mel.eval( 'getenv "%s"' % name )
print "\tbefore: %s" % originalPath
modifiedPath = os.path.join( perforceDepot, path )
if originalPath != "":
modifiedPath = ";".join( (originalPath, modifiedPath) )
melCommand = 'putenv "%s" "%s"' %(name, modifiedPath)
melCommand = melCommand.replace( "\\", "\\\\" )
mel.eval( melCommand )
modifiedPath = mel.eval( 'getenv "%s"' % name )
print "\t after: %s" % modifiedPath


And the output from the Output Window when maya starts up looks correct:

MAYA_SCRIPT_PATH
before: C:/Documents and Settings/Rob/My Documents/maya/projects/default/mel;C:/Documents and Settings/Rob/My Documents/maya/2009/scripts;C:/Documents and Settings/Rob/My Documents/maya/scripts;C:/Documents and Settings/Rob/My Documents/maya/2009/presets;C:/Documents and Settings/Rob/My Documents/maya/2009/prefs/shelves;C:/Documents and Settings/Rob/My Documents/maya/2009/prefs/markingMenus;C:/Documents and Settings/Rob/My Documents/maya/2009/prefs/scripts;C:/Program Files/Autodesk/Maya2009/scripts;C:/Program Files/Autodesk/Maya2009/scripts/startup;C:/Program Files/Autodesk/Maya2009/scripts/others;C:/Program Files/Autodesk/Maya2009/scripts/AETemplates;C:/Program Files/Autodesk/Maya2009/scripts/unsupported;C:/Program Files/Autodesk/Maya2009/scripts/paintEffects;C:/Program Files/Autodesk/Maya2009/scripts/fluidEffects;C:/Program Files/Autodesk/Maya2009/scripts/hair;C:/Program Files/Autodesk/Maya2009/scripts/cloth;C:/Program Files/Autodesk/Maya2009/scripts/live;C:/Program Files/Autodesk/Maya2009/scripts/fur;C:/Program Files/Autodesk/Maya2009/scripts/muscle
after: C:/Documents and Settings/Rob/My Documents/maya/projects/default/mel;C:/Documents and Settings/Rob/My Documents/maya/2009/scripts;C:/Documents and Settings/Rob/My Documents/maya/scripts;C:/Documents and Settings/Rob/My Documents/maya/2009/presets;C:/Documents and Settings/Rob/My Documents/maya/2009/prefs/shelves;C:/Documents and Settings/Rob/My Documents/maya/2009/prefs/markingMenus;C:/Documents and Settings/Rob/My Documents/maya/2009/prefs/scripts;C:/Program Files/Autodesk/Maya2009/scripts;C:/Program Files/Autodesk/Maya2009/scripts/startup;C:/Program Files/Autodesk/Maya2009/scripts/others;C:/Program Files/Autodesk/Maya2009/scripts/AETemplates;C:/Program Files/Autodesk/Maya2009/scripts/unsupported;C:/Program Files/Autodesk/Maya2009/scripts/paintEffects;C:/Program Files/Autodesk/Maya2009/scripts/fluidEffects;C:/Program Files/Autodesk/Maya2009/scripts/hair;C:/Program Files/Autodesk/Maya2009/scripts/cloth;C:/Program Files/Autodesk/Maya2009/scripts/live;C:/Program Files/Autodesk/Maya2009/scripts/fur;C:/Program Files/Autodesk/Maya2009/scripts/muscle;C:/working/depot/Tools/Maya/MelScripts
MAYA_PLUG_IN_PATH
before: C:/Documents and Settings/Rob/My Documents/maya/2009/plug-ins;C:/Documents and Settings/Rob/My Documents/maya/plug-ins;C:/Program Files/Autodesk/Maya2009/bin/plug-ins
after: C:/Documents and Settings/Rob/My Documents/maya/2009/plug-ins;C:/Documents and Settings/Rob/My Documents/maya/plug-ins;C:/Program Files/Autodesk/Maya2009/bin/plug-ins;C:/working/depot/Tools/Maya/Plugins/2009
XBMLANGPATH
before: C:/Documents and Settings/Rob/My Documents/maya/2009/prefs/icons;C:/Documents and Settings/Rob/My Documents/maya/prefs/icons;C:/Program Files/Autodesk/Maya2009/icons;C:/Program Files/Autodesk/Maya2009/app-defaults;C:/Program Files/Autodesk/Maya2009/icons/paintEffects;C:/Program Files/Autodesk/Maya2009/icons/fluidEffects;C:/Program Files/Autodesk/Maya2009/icons/hair;C:/Program Files/Autodesk/Maya2009/icons/cloth;C:/Program Files/Autodesk/Maya2009/icons/live;C:/Program Files/Autodesk/Maya2009/icons/fur;C:/Program Files/Autodesk/Maya2009/icons/muscle
after: C:/Documents and Settings/Rob/My Documents/maya/2009/prefs/icons;C:/Documents and Settings/Rob/My Documents/maya/prefs/icons;C:/Program Files/Autodesk/Maya2009/icons;C:/Program Files/Autodesk/Maya2009/app-defaults;C:/Program Files/Autodesk/Maya2009/icons/paintEffects;C:/Program Files/Autodesk/Maya2009/icons/fluidEffects;C:/Program Files/Autodesk/Maya2009/icons/hair;C:/Program Files/Autodesk/Maya2009/icons/cloth;C:/Program Files/Autodesk/Maya2009/icons/live;C:/Program Files/Autodesk/Maya2009/icons/fur;C:/Program Files/Autodesk/Maya2009/icons/muscle;C:/working/depot/Tools/Maya/Icons
MAYA_SHELF_PATH
before:
after: C:/working/depot/Tools/Maya/Shelves/2009
PYTHONPATH
before:
after: C:/working/depot/Tools/Maya/Python


But I am not seeing several shelves defined in C:\working\depot\Tools\Maya\Shelves\2009 showing up as I would expect.

If I forgo the userSetup.py file and do everything in a Maya.env file, as show below:

# Update with the local location of your perforce depot.
PERFORCE_DEPOT = C:\working\depot

MAYA_SHELF_PATH = %PERFORCE_DEPOT%\Tools\Maya\Shelves\2009
MAYA_SCRIPT_PATH = %PERFORCE_DEPOT%\Tools\Maya\MelScripts
XBMLANGPATH = %PERFORCE_DEPOT%\Tools\Maya\Icons
MAYA_PLUG_IN_PATH = %PERFORCE_DEPOT%\Tools\Maya\Plugins\2009
PYTHONPATH = %PERFORCE_DEPOT%\Tools\Maya\Python

...it works and I see the custom shelves.

Why does using the userSetup.py approach not load the custom shelves?

I'm using Maya 2009 on Windows XP.

Joviex
01-23-2011, 05:33 AM
Why does using the userSetup.py approach not load the custom shelves?


Because the Python interpreter for Maya (mayapy.exe) starts up AFTER the environment variables are loaded.

The extra gotcha is that Maya loads the shelves during the userSetup.mel stage (also before userSetup.py), so it uses the variables it has before you can change them via python.

All you have to technically do is re-parse the shelf paths and load them yourself.

Not 100% sure where to look, but I am sure a whatIs on some of the shelf commands will reveal all.

HTH.

gordrob
08-02-2011, 10:21 PM
That makes sense, although it makes me sad that there is such big difference between userSetup.mel and userSetup.py.

I was looking at the MEL scripting command for shelves and loadNewShelf seems like what I want, but it makes a copy of that shelf's .mel file into the user's maya folder. Since we have our shelves under source control, I want maya to always load that shelf from a particular location, not load it once from there and then use a local copy.

I'm not sure what you mean by a "whatIs" command. Could you elaborate?

bendingiscool
08-03-2011, 02:41 PM
whatIs is a command you can run on your shelf scripts to get there location, eg..

whatIs doCreateNCloth;
// Result: Script found in: /software/maya/2011.5/linux.centos5.x86_64/scripts/others/doCreateNCloth.mel //

cheers,
Chris

ThePistolPete
08-03-2011, 04:58 PM
It is possible to setup your environment via a external shell-script (on windows cmd-files) and launch Maya with it. Alternatively you can use a standalone python script which will do the same.

CGTalk Moderation
08-03-2011, 04:58 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.