Global proc and proc

I've created a whole UI in a MEL script with a few global proc's and a number of proc's. If I load this script and execute it, it works just fine.

If I restart Maya, load another script which refers to a global proc in my first script, it appears to load the global procs alright, but then can't execute any of the procs as they're undefined(?).

What's the point of proc, should I have to make everything in a script global?

Pete Goodwin, Sensaura

I think the problem is that both scripts have to be executed in order for the second one to access any procs declared in the first.

g

yeah, in my experience, procs are utterly useless. which seems pretty dumb. I've never actually successfully used one in any of my scripts. I think they might be more useful for scripts that don't need UI though.

That worked, thanks.

Pete Goodwin, Sensaura

I work around enough programmers that it has rubbed off on me to use as few global variables or procedures as possible.

A local proc has to be declared in the same script that uses it and it must be declared before the global proc. Most of my scripts are built with a global proc that launches a UI and global proc for each button. My button press code usually will consist of running a local proc. I find it very useful to encapsulate code into little procedures so I can use the the bits in different ways.

I just uploaded a script called importCleaner.mel. If you take a look at how I set this up, you can see how I structure my scripts with local procs and how they can be useful. Especially useful for demonstrating this is the ic_dupeTest procedure. It does a check on the input string to see if there are similarily named objects in the scene. I use this procedure in for different types of input throughout.

One other thing heavy procedure use can do is make your code very easy to read by others. If you look at importCleaner, you will see that that the main procedure ic_UIgo is just comments explaining the large steps that the script will go through while the meat of the code has been encapsulated into local procedures so as not to clutter this main procedure. This helps readabilty of the code - especially when used with effective commenting

Hopefully, this example can be helpful to some out there.

--JeffD