Share
 
 

Execute external MEL script files

You can run MEL scripts as separate files. They have the extension .mel by default.

You can execute external script files in two ways:

  • In the Script Editor, select File > Source Script.
    Note: Before executing scripts, make sure you save any data you were working on.

    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.

  • Place the script in one of Maya’s standard script directories.

    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.

    Note: MEL scripts and mayaAscii files are different things. If you rename a .ma file to a .mel file and source it, you may get errors. Alternatively, if you rename a .mel script to be a .ma file and open it, you may get errors or even crash Maya. Maya does special things while reading files to improve performance and not all commands are compatible with this.

Related topics

Was this information helpful?