Trouble loading scripts from userSetup and userPrefs

I have a .bat file which sets a PYTHONPATH env variable and opens a specific maya.exe version that our team uses. Within the PYTHONPATH there is a file which runs a load shelf command within a evalDeferred function. It loads fine in a clean maya env without a lot of custom shelves and prefs but does not load if an animator has custom shelves. I’ve copied the animators maya prefs folder and can repro the problem but not sure what the solution is.

The expected result is that maya will load all the shelves in the user prefs and run the load shelf command in the I’ve specified.

The actual result is that only the shelves in the userPrefs.mel will load.

If I delete the userPrefs.mel the shelf loaded from appears.

I’m not sure the loading order or what is happening in the userPrefs to stomp any other shelves from being loaded on startup.

Any advice?


The .bat file and PYTHONPATH aren’t the way to go for this, I think. What you should probably do is use a module, which you will define in a .mod file.

So first, what is a module? Well, you already use them. Folders like Documents/maya/2022 are basically modules. They’ve got folders for prefs, plug-ins, scripts, shelves, etc. And it auto loads Modules follow that exact same folder structure, but give you more control.

Maya has an environment variable MAYA_MODULE_PATH. Any .mod files it finds in the folders on that path are treated as modules.

With a mod file, you can filter by different versions of maya and different OS’s. So you could say “For Maya 2022 on linux, add this folder to the MAYA_PLUG_IN_PATH, but for Maya 2022 on Windows, add this folder instead”. You can also create or add to any environment variables. Or you could say that instead of looking in the folder plug-ins for plugins, it should look in a folder named bob, or maya22Plugins, or whatever, or 2022/win64/plug-ins.

Also, you won’t have to use a .bat file because this will happen any time maya starts.

For your use-case, I suggest adding a folder to the MAYA_SHELF_PATH variable instead of using the built-in shelves folder. In the shelves folder, any time an artist closes maya, it will try to save a copy of that file to their Documents/maya/20??/shelves and they start getting duplicates. That doesn’t happen with the MAYA_SHELF_PATH (this is something that I’m dealing with at work right now)

So the contents of your .mod file would look something like:

+ MAYAVERSION:2020 PLATFORM:win64 animShelves 0.0.1 ./animShelves
MAYA_SHELF_PATH +:= customShelves/maya2020

+ MAYAVERSION:2023 PLATFORM:win64 animShelves 0.0.1 ./animShelves
MAYA_SHELF_PATH +:= customShelves/maya2023

So reading that first line from left to right: For maya 2020 on windows, make a module named “animShelves” with version “0.0.1” looking in the folder ./animShelves (notice it’s a relative path!)

The next line uses this strange thing +:= to mean “append this relative path to the environment variable”. So a folder ./animShelves/customShelves/maya2020 would get added to your MAYA_SHELF_PATH.

Then you’ve just gotta put the shelf files in those folders.

Unfortunately, the documentation for modules is TERRIBLE, but here’s a link.

1 Like

Thank you, I appreciate it! I’m going to dig into modules as a solution.

Modules is def the way to go!