Auto SOURCE-ing


My MEL book is in route, and while I wait, I’ve been playing with other MEL scripts.

The first thing I noticed with MEL is this SOURCE command, the fact that Maya loads the functions into memory automatically. The problem though, is that if I make changes to my script, I cannot just run the script again. The second time I run the script it wont re-source, or over write the function in memory.

So how do you get around this problem while developing a MEL script? It looks like I can place a SOURCE command right in my MEL script, but I’m looking for an even simplier solution. I’d rather my functions NEVER load into memory. I’d rather the script always reload the files from my hard drive, that way I can just edit the files, and then execute my new changes.



#2 <-- check the tut and you’ll have an understanding on how auto-sourcing works :slight_smile:


I don’t think you understand. So try this:

Create a new MEL script titled TEST.MEL. Place this code inside it:

global proc test () {
print "Yeah! It sourced!

save the file and then run test from within Maya. You should see:

Yeah! It sourced!

in the Script Editor window. Now lets act like you are building a MEL solution in Maya. Let’s make a change to your script. Change test.mel to:

global proc test () {
print "But does it always auto-source?

Save the file, and try running it again. What happens? On my machine, NOTHING happens. Well actual what appears is:

Yeah! It sourced!

Why is that? Because it didn’t auto-source the 2nd time. So are you telling me EVERY time I change a script in Maya I have to source each file before my solution works correctly? What happens when my solution contains 20-30 source files?

I’m hoping someone knows a way to FORCE Maya to auto-source every MEL script, every time, so I can simple make a change, test it, make a change, test it. Or at the very least tell me the best way around this annoyance.

Hope that explains it better, -=STZ=-


hmm could you do something like have a virtual funct that reads a file from the hd and performs eval on the characters? that’s a pretty ugly though.



well, i usually have a little script that is used to test a script(s) during development …, it has eval(“source scriptx”);s in it [nb the use of eval], usu something to prep the scene ready to test, and then finally a call for the test.

ie - you have to explicitly resource the file after you’ve saved a change to it on disc. if you wanted, perhaps you could open a commandPort and get your editor to pass the file contents through the port ea. time you saved a file …that way you’d have the lattest versn sourced (or, just send a source thisfile.mel upon save …hmm, i best give that a try! …tho it takes nothing to add sourceings in your test script.).



stzaske: how did you end up getting around the problem you were having?


check out zooScriptLoader. it lets you manage scripts within maya, as well as offering you auto-sourcing through its UI. i haven’t yet used it in maya 6 which requires a rehash when you create a new script, so keep that in mind.


you have to source it again.

//resource your script
source test;

add that to a shelf button and you got yourself a solution

Found that on point 10


Actually, when your solution contains many source files is when you should be most grateful for this behavior. If Maya had to re-examine each file to determine whether it had changed every time you ran an affected procedure, EVERY procedure call would be affected and your scripts would be extremely slow!

What you can do to make manually sourcing a lot of files easier is make a file that contains a bunch of source statements, then source that one file. Or, if you know you’ve only changed three files, just have Maya re-read those.

– Mark


i have a bunch of scripts that i’ve written that have 20 or so other scripts that it depends on. I’ve gotten in the habit of writing a “dependencies” procedure, which basically just returns the names of all the scripts it depends on. Then when the UI to that script is opened, it calls the dependencies proc, sticks the resulting dependent scripts into an array, and then sources each dependent.

so something like this:

global proc string[] dependencies(){
 string $deps[];
 $deps[( `size $deps` )] = "zooUtils";
 $deps[( `size $deps` )] = "someOtherScript";
 $deps[( `size $deps` )] = "bananas";
 return $deps;
 string $deps[] = `dependencies`;
 for( $a in $deps ) eval( "source "+ $a );

The advantage of doing this, is that i can easily query which scripts rely on each other. re-sourcing 20 or 30 scripts is actually lightning fast. its just the initial sourcing that takes time. If you’re interested in the finer details, check out zooCST. When you first load zooCST, it sources all its dependent scripts.


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.