Mel commands under Python or vice versa

85 views
Skip to first unread message

DGFA DAG's GRAPHIC & FOTO ART

unread,
Aug 26, 2022, 6:58:10 PM8/26/22
to Python Programming for Autodesk Maya
Hi,

I struggle with a custom menu. I will to have my own menu with all the stuff I have in several shelfs. But when I codethe menu in Mel I don’t know how to set the command attribute for executing a Mel  command. 
For example:
Mel
menuItem -p $mainWindow -l "Set Project" -c "SetProject"
menuItem -p $mainWindow -l "Create Material" -c "source mat.py"

The first line works fine the second throws an error "file mat.py not found"

How can I solve this?

Thanks,
Dag

vince touache

unread,
Aug 26, 2022, 7:34:10 PM8/26/22
to python_in...@googlegroups.com
I don't have a maya available to test it currently, but did you try to run your command via the "python" keyword in MEL?
Calling, in MEL:
python "import mat;mat.do_something()" 
should be understood correctly by your MEL call, I assume


--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/fe306d38-7042-4206-8656-b105c298d1a8n%40googlegroups.com.

DGFA DAG's GRAPHIC & FOTO ART

unread,
Aug 27, 2022, 2:15:14 AM8/27/22
to Python Programming for Autodesk Maya
When I do this I get an error "Error line 1.35 Syntax error"
When I run his line as standalone python("import mat"; mat.run()"
this is working but I need a command for the menuItem that runs Mel commands or python command/script.

In Maya documentation there are examples for menu but no one have the flag -c included.

DGFA DAG's GRAPHIC & FOTO ART

unread,
Aug 27, 2022, 2:27:16 AM8/27/22
to Python Programming for Autodesk Maya
In Python it works with Mel commands when I do this
pm.menuItem(label=‘my menu’, command="mel.eval(‘SetProject’)")

Kenneth Ibrahim

unread,
Aug 27, 2022, 12:55:05 PM8/27/22
to python_in...@googlegroups.com
Not sure if this is applicable in this case, but PyMEL has this great MEL access mechanism that essentially turns any MEL command into a Python function complete with arguments:

pm.mel.melCommandName(arg1, arg2, argN)




--
"God is a metaphor for a mystery that absolutely transcends all human categories of thought. It's as simple as that!" - Joseph Campbell

DGFA DAG's GRAPHIC & FOTO ART

unread,
Aug 27, 2022, 3:35:53 PM8/27/22
to Python Programming for Autodesk Maya
Hi,

thank you!
I found a undocumented flag for menuItem in mel -sourceType "python".

This works as well in python
pm.menuItem(label='Match Rotation', sourceType='mel', command='MatchRotation')
pm.menuItem(optionBox=True, visible=False, sourceType='mel', command='MatchRotationOptions')

Justin Israel

unread,
Aug 27, 2022, 5:36:49 PM8/27/22
to python_in...@googlegroups.com
DGFA DAG's GRAPHIC & FOTO ART schrieb am Samstag, 27. August 2022 um 08:15:14 UTC+2:
When I do this I get an error "Error line 1.35 Syntax error"
When I run his line as standalone python("import mat"; mat.run()"
this is working but I need a command for the menuItem that runs Mel commands or python command/script.

In Maya documentation there are examples for menu but no one have the flag -c included.

There are examples of using the python() MEL function in the MEL docs:
https://help.autodesk.com/cloudhelp/2022/ENU/Maya-Tech-Docs/Commands/python.html

However, if you are coding your menu in MEL and you want to have your menuItem use a python syntax callback, then you should check the documentation for menuItem:
https://help.autodesk.com/cloudhelp/2022/ENU/Maya-Tech-Docs/Commands/menuItem.html

You will notice that there is a   -sourceType(-stp)   flag that allows you to tell the menu to use python for the callback syntax:

menuItem -p $mainWindow -l "Create Material" -sourceType "python" -c "import mat; mat.do_something()"

Reply all
Reply to author
Forward
0 new messages