You can run MEL scripts as separate files. They have the extension .mel by default.
You can execute external script files in two ways:
When you source a MEL script, MEL does not allow you to forward reference locally scoped procedures. Locally scoped procedure definitions must appear before they are called. For example, in a file called noForwardRef.mel, define the local procedures before they are referenced.
proc myLocalProc() { print "In myLocalProc()\n"; } proc anotherLocalProc() { print "In anotherLocalProc()\n"; myLocalProc; } global proc noForwardRef() { print "Calling anotherLocalProc()\n"; anotherLocalProc; }
If you change a script after sourcing it, the change is not automatically picked up by Maya. You need to re-run the script with File > Source Script.
When you type the name of the file, Maya sources the contents of the file, and if a procedure with the same name exists in the file, Maya executes it. This lets you create scripts that work like built-in commands.