Feedback

What's your question?

By: [ Editor ] Asked

Python to MEL: Is it possible to source a python file through a MEL menuItem?

I was asked by my group to write some Python plugins for Maya that would be launched through a menu (NOT the shelf editor) as a menuItem. The scripts themselves are done and working fine, but the menu they need to launch from is a MEL UI. The MEL UI is too massive for me to convert into Python on such short notice. Here's what I have within the menu:

    menu -label "Export/Import";
menuItem -label "Export Lights" -sourceType \"python\" -c "\"itemPath/item_export\"";
menuItem -label "Import Lights" -sourceType \"python\" -c "\"itemPath/item_import\"";

The files I'm trying to reference are item_export.py and item_import.py. Of course I've already discovered that -sourceType "python" does not work on menuItems (only on shelf buttons) so I'm totally stuck. Am I screwed or is there a way to launch a python script through a MEL menuItem? The python scripts are initialized so if I need to access item_import.main() I can, does that make a difference in this case? Any help in this matter would be greatly appreciated. Thank you!

Add comment viewed 412 times Latest activity 11 months ago

or Cancel

2 answers

  • 1

merc [ Editor ]

Thanks michal for your script! I was actually able to find the answer to my question. For anyone who is curious, here is the solution. Reminder, this is for Python being run inside MEL:

menu -label "Export/Import";
menuItem -label "Export Lights" -c "python(\"commands\")";
menuItem -label "Import Lights" -c "python(\"commands\")";

It's a pain that there is zero documentation on this online, so hopefully someone else will find this helpful. Thanks all!

or Cancel
  • 0

michalf [ Editor ]

Hi Merc I'm not sure if this is of any help, but I have a nice script to build menus. It's advantage is that you build hierarchy of menus by making a tree of directories (menus) and text files inside (menu items). Each text file is just a MEL code that gets sourced whenever you click menuitem, so you can do anything inside - for example: python "UVShellsUtilsWin()" Also you can easily restructure menus by moving files, and have per-project setups

Have a look at it, it's very straightforward

http://michalf.superhost.pl/menuMaker.rar

or Cancel