Setting a global environment variable

We do the same by simply using Maya’s module system… a text file in the module folder like any other 3rd party plug-in and your set.

We avoid any modifications to the maya application folder and prefer to use a python script to update the various maya env variables. we did try modules for awhile, but setting up new machines required running a batch process to ensure the module files made it to the correct folder.
Now we just have 1 script that runs through a series of steps to configure the environment and then calls maya with start-up script to add new UI elements and start script jobs.

[QUOTE=stev;10487]I had to use ctypes since I can’t use win32com or gui (long story). Thanks again.


from ctypes import *

HWND_BROADCAST = 65535
WM_SETTINGCHANGE = 26
SMTO_ABORTIFHUNG = 2

result = c_long()
user32dll = windll.user32

user32dll.SendMessageTimeoutA(HWND_BROADCAST, WM_SETTINGCHANGE, 0, 'Environment', SMTO_ABORTIFHUNG, 100, byref(result))

Stev[/QUOTE]

Pure gold. We also avoid win32 due to the extreme pain it causes. For posterity in addition to adding and refreshing env vars there is also a ctypes implementation of deleting them here:

i had to work around this as well, i like the broadcast message, seems better than my hack. basically i edit the registery using the command line then call

setx /m A A

That will broadcast the same(?) message to let windows know the registry has changed. Does anyone know why there is a 1024 character limit to setx?

just don’t hand such scripts to outsourcers. It’s not uncommon that artist machines run with limited permissions. E.g. things like registry edits or messign with global variables is not permitted unless you do it from a signed installer - e.g. one created with NSIS or a .msi.

If you don’t offer an option to clean up such system wide modifications (e.g. at script end, or with an uninstaller), it’s also pretty bad style :wink:

Yeah, the cheapo solution remains a .bat file:


SET UL_PROJECT=class4
SET UL_BRANCH=networked
SET MAYA_DEV=C:/ul/tools/python/ulMaya
maya

Nice thing about that is you can run two different project versions of maya or whatever side by side (although I can’t convince my users to let me change their color setting so it’s easier to tell which is which :slight_smile: )