automatic script sourcing on maya launch

by Spot on 25.06. '08

if you have extended your maya with several mel scripts (if not, you certainly will one day!), it’s useful to source those automatically when launching maya, so you can access them right ahead instead of manually sourcing them whenever you need one or the other.

the best way to do this is by creating an empty text file called userSetup.mel within your personal scripts folder (usually c:\users\[yourusername]\documents\maya\2008\prefs\scripts) and add this:

source "nicescript.mel" ;

just copy the line and add further script file names to it and next time you start maya, all those scripts are ready to go!

{ 2 comments… read them below or add one }

brubin1 23.10. '09 at 6:24 am

hmmm,
source order in maya is a bit more complex than that….

first up – if you have set system based environment variables to wherever your maya installation resides, -which is normally done by the maya installer when your installation goes as intended- then maya finds the following folder containing MEL scripts in this order:

- program-folder: print(`getenv “MAYA_LOCATION”`+”/scripts/*”);
- user script-directory: print( `internalVar -userAppDir`+”scripts”);
- maya version specific script-directory: print( `internalVar -userScriptDir`);

although the may-version specific scripts-folder gets sourced last i prefer to put my scripts in the second location, because i don’t need to copy any scripts to any new directory when another maya-version comes out- this directory gets sourced by them all!

so there’s really no need to specifically source a scripts like that, unless of course you want to RUN the script on maya-startup!
that’s something competely different, though!

it is considered good practice however not to run scripts by simply sourcing them. that has to do with the automatic sourcing process described above: every script in those folders get sourced on maya startup- make no mistake about that! so, better do it like this:
eval( “source \”"+`internalVar -uad` + “scripts/nicescript.mel\”") ;

and if this were a shelfbutton, or if you wanted to run it on startup, you would add the call to the function as well:
nicescript();

in early versions of maya your version of the ’source’ command worked like you typed it; nowadays ’source’ often fails for reasons that escape me right now, but with ‘eval’ i never had these problems!

HIH
b.

Spot 23.10. '09 at 7:47 am

thanks for your detailed explanations! definitely very helpful.

Previous post: target weld function in maya

Next post: time to learn python