How to go about safely calling procedures defined in shelft items elsewhere?

Lately I have been dealing with a situation where, I will try to call a function, whose definition only exists in a shelf item, via a hotkey or the script editor or in other places, etc etc. And I will end up getting an error:

// Error: Cannot find procedure "hello".

If this was an isolated instance, I would be fine with it but its something I am dealing with constantly, I have a few scripts I have bought/created that are only stored in shelf items. So this creates a problem where, if I have so far not called the function by clicking the shelf item, I will get an error.

A solution that comes to mind is to just copy and paste these definitions to the custom scripts (“hotkey editor” > “custom scripts”) window but this just moves the problem to another location. As I then, would not be able to call the procedure from the shelf, the script editor, etc etc.

I will have to

I am essentially asking for a design or a solution, where as soon as I start the Maya programme, I can call a procedure that is saved in the shelf from the script editor. Furthermore, avoid repetition work, where every time a developer updates their tools, I have to update it at multiple locations.

If such a feature is not available, then I would like to hear how you guys approach this issue, surely I am not the only one that has confronted it.

What I tired: I thought the global keyword was for this very purpose. I tested it by saving a procedure in a shelf item and trying to call it in the script editor, and I get the above error:

global proc hello3(){
	print("\n hello world \n");
}
hello();

Am on Maya 2025, thanks for any input.

If you save it as MEL file with exactly the same name as your global proc (“hello3.mel” in this case), in a directory where Maya looks for MEL scripts, you can call it from anywhere inside Maya, by simply typing the name of procedure:

hello3()

Maya will look for a file with that name, and for a global procedure with that same name inside that file, and execute it, if found.

Be sure to restart Maya, after saving MEL file, so it knows about your new script, or force a “refresh” by running (in which case, restart isn’t needed):

rehash()

Also, if you have more global procedures inside a script, and you want to execute them, you’d need to source that file first (same goes if you type hello3(), but you’ve saved MEL file under different name, which will again error as “Cannot find procedure…”, unless you source that file first):

source hello3

This will give you access to all global procedures inside that MEL script, which you could now run simply by typing their names:

other_global_proc_defined_in_hello3_file();
and_another_global_proc();
// etc.

P.S. Non-global procedures won’t be available to call from outside of the script.

1 Like

Had to drop Maya for a few days, completely missed this great answer. Solved my issue to say the least. Thank you for this answer!