Why is it, that if I put a script somebody else made into my scripts folder they run fine. But as soon as I make a script as simple as:
print "Hello World";
and try run it from a MEL file, it comes up with the error:
// Error: Cannot find procedure "xxxxxxxx". //
where xxxxxxxx is the MEL file.
Any idea why this happens? I tried putting the command in a proc () and that didn't work. Then I tried putting it in a global proc () and that did, but as soon as I tried calling a proc () from within the global, it wouldn't find it.
Also, I tried creating a UI within the global proc and that doesn't work either, but it does if I run the script from script editor. Any idea whats going on?
ok, so let's say you have a script named xxxxxxxx.mel in your scripts directory. When you enter in "xxxxxxxx" in the command line, Maya tries to execute a proc named "xxxxxxxx". If it doesn't find such a proc, then it looks for a mel file called "xxxxxxxx.mel" and tries to execute the proc xxxxxxxx in that .mel file. If there is no such xxxxxxxx proc in that file, you get an error.
So: If you need a one shot script, use "source xxxxxxxx". Maya will execute all commands in xxxxxxxx.mel, such as print "Hello World".
If you want to use a global proc named xxxxxxxx, put it either in a file called xxxxxxxx.mel, and just call it. Or put it in a file called yyyyyyyy.mel, and source yyyyyyyy; then then you can use xxxxxxxx. If you want to use a proc only within a file, just don't make it global.
Maya needs to know where it can find a proc. You tell Maya by either sourcing the file (then it remembers this), or by letting the file have the same name as the proc.
Did you put the script in a place where Maya 6 can find it? If the script is installed in your Maya 5 folder or the Maya5/scripts folder in your user directory Maya 6 will not know where it is.
If you name the script gridFix.mel and type gridFix then it's no wonder you are gettign error.. you ahve to type the name of an actual procedure.
I think Global Procs can only see otehr Global procs but I'm not sure so if you make gridAdjust a global you will have to make any that it calls upon global as well.
If oyu put the gridFix.mel in your scripts directory it's loaded when Maya is launched you don't have to call it.. you do have to call the correct proc names.
If you want your main proc to be named gridFix then name it that... I think youneed to make it a global and the other it calls may not need to be..
what do you mean by "won't do any of the other procedures"? gridFix is the only global proc, so it's the only proc visible outside of the script. The UI is outside of the script, even though you create the UI in the script. But when you press a button in the UI, this button is not part of the script, so when the button calls a proc in the script, you have to make it global.
Make every proc global that's called from outside, then it should work.
so a proc () (not global) can't be used with UI? Not when the UI calls it anyway? The proc can only be used if its being called during the execution of the script?
Thanks. I found that even if I globalise all procedures in the script, it would still only run the first one. But if I did the source command it would work.
It's weird. It must be a new restriction on Maya 6 as Maya 5 never had that problem. I could put non global procedures in an external MEL script file, run it from within Maya and it would work fine. Now to run it, I need to run the source command first.
yea, its weird the only thing i can think of is that maya 5 had more relaxed procedure conditions. I guess it's not a bad thing.
What confuses me now is, if you have to globalise all procedures, what's the point in having the option of not putting 'Global' in front of the proc function?
I can't get a global proc to call non-global procs. I can only refer to what another replier wrote in saying that the UI script can't call non global procs after the script is finished, simply because the script creates the UI, then the script finishes and the other procs no long exist.
In which case, non global procs can't be used with UI scripts unless they are called during the running of the script and not after.
Does that make any sense or am I rambling? I'm not very good at expressing thoughts.
creating the script is fine.. but do you have to close and restart maya everytime you create a new script?? is there a way to make maya see the file without re-running the program? Everytime I create a script, maya won't find it until I re-run maya. its very annoying.
Offcourse you can call non global procs UIS just cant call then sice they do not reside inside the prc structure anymore since they are on the global temlate of maya
now, without the final 'test;' command to call the test proc, it will source fine. but if i source it with that command, it errors, saying it can't find proc yo.
Which means source doesn't globalise all procedures. If I source it without the 'test' proc call, then run the test procedure from maya, it can't find the yo proc which is understandable. but why can't the source command find it either?