mayamel

How to get the path of a drag & dropped file in Maya's MEL


Drag & drop a Maya MEL file into Maya and the contents of the MEL file will be executed. Is there a way to get the absolute path of the file when dragging and dropping?


Solution

  • Hopefully this can get you started

    test.mel:

    global proc FindMe() {}
    
    print("whatIs result -> " + `whatIs "FindMe"`);
    

    Drag-dropping the file into Maya produces the following output:

    > source "C:/Users/itypewithmyhands/Desktop/test.mel";
    > whatIs result -> Mel procedure found in: C:/Users/itypewithmyhands/Desktop/test.mel
    

    Interesting points to note:

    1. Drag-drop seems to simply produce a source <file> statement, which means you'll have to do some internal magic unknown to me in order to know if the file was actually dropped, or simply sourced
    2. The proc you search for has to be marked global

    You need to regex (or similar) the result of the whatIs command to get the path you're after. Something like .*found in: (.+?\.mel) seems to work well enough. Example