popupMenu command works in Python but not in Mel

154 views
Skip to first unread message

likage

unread,
Jul 26, 2018, 4:01:24 PM7/26/18
to Python Programming for Autodesk Maya
I was trying to convert a popupMenu command from Python to Mel..

When using Python:
cmds.popupMenu( button=1, postMenuCommand="import lod_select; lod_menu = lod_select.make_dropdown(); lod_select.show_menu(lod_menu)")


However, when I tried converting the above command into MEL, I get an error:
# Keeps getting error output of "Invalid use of Maya object "lod_menu"
popupMenu
-button 1 -postMenuCommand "import lod_select; lod_menu = lod_select.make_dropdown(); lod_select.show_menu(lod_menu)";


Any ideas?

Robert White

unread,
Jul 26, 2018, 4:22:18 PM7/26/18
to Python Programming for Autodesk Maya
I believe the problem you're running into here, is that the popupMenu -postMenuCommand expects the command to be in mel, because you're triggering it from mel.

likage

unread,
Jul 26, 2018, 4:44:09 PM7/26/18
to Python Programming for Autodesk Maya
I see... Any possible way that I can make it to evaluate in Python?

Simon Payne

unread,
Jul 26, 2018, 4:53:11 PM7/26/18
to python_in...@googlegroups.com
Yup, as Robert says. You can cast a python command though :

-postMenuCommand = “python ‘myCommand()’”

Simon

Sent from my iPhone
--
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/6114e628-0030-4a87-813a-c9b0dc03125d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

likage

unread,
Jul 26, 2018, 5:14:53 PM7/26/18
to Python Programming for Autodesk Maya
Doesn't seems to work... Getting the same error...


On Thursday, July 26, 2018 at 1:53:11 PM UTC-7, simon payne wrote:
Yup, as Robert says. You can cast a python command though :

-postMenuCommand = “python ‘myCommand()’”

Simon

Sent from my iPhone

On 26 Jul 2018, at 21:22, Robert White <robert....@gmail.com> wrote:

I believe the problem you're running into here, is that the popupMenu -postMenuCommand expects the command to be in mel, because you're triggering it from mel.


On Thursday, July 26, 2018 at 3:01:24 PM UTC-5, likage wrote:
I was trying to convert a popupMenu command from Python to Mel..

When using Python:
cmds.popupMenu( button=1, postMenuCommand="import lod_select; lod_menu = lod_select.make_dropdown(); lod_select.show_menu(lod_menu)")


However, when I tried converting the above command into MEL, I get an error:
# Keeps getting error output of "Invalid use of Maya object "lod_menu"
popupMenu
-button 1 -postMenuCommand "import lod_select; lod_menu = lod_select.make_dropdown(); lod_select.show_menu(lod_menu)";


Any ideas?

--
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_maya+unsub...@googlegroups.com.

likage

unread,
Jul 26, 2018, 6:12:34 PM7/26/18
to Python Programming for Autodesk Maya
Adding in a bit more information.

My objective initially is to have a shelfButton to have 2 different selection menus.
1. If User clicks on the shelf button, it will shows menuA...
2. If User clicks on the shelf button while pressing "ALT" key, it will shows menuB...

My initial code, where it keeps giving off the error of unable as mentioned in my first post...
shelfButton
       
-enableCommandRepeat 1
       
-enable 1
       
-noDefaultPopup
       
-width 34
       
-height 34
       
-manage 1
       
-visible 1;


// menuA options (only left mouse click on the shelf button)
popupMenu
-button 1 -postMenuCommand "import lod_select; lod_menuA = lod_select.make_dropdownA(); lod_select.show_menu(lod_menuA)";


// menuB options (alt key + left mouse click on the shelf button)
popupMenu
-button 1 -alt 1 -postMenuCommand "import lod_select; lod_menuB = lod_select.make_dropdownB(); lod_select.show_menu(lod_menuB)";




Seeing that this is not working, thought I made the shelfButton to have a default command that it will load menuA.
This seems to work to my cause, however it seems that while trying to access menuB options, I will need to select 2 time before the menuB options are presented to me.

If I click on the shelf button, it will shows a menu titled "menuitem1993", clicking on that, will it then be showing me the actual menu items of menuB,.. How can I bypass this "menuitem1993" creation?

shelfButton
       
-enableCommandRepeat 1
       
-enable 1
       
-noDefaultPopup
       
-width 34
       
-height 34
       
-manage 1
       
-visible 1
 
-sourceType "python"
 
-command "import lod_select; lod_menuA = lod_select.make_dropdownA(); lod_select.show_menu(lod_menuA)";


// menuB options (alt key + left mouse click on the shelf button)
popupMenu
-button 1 -alt 1;
menuItem
-sourceType "python" -command "import lod_select; lod_menuB = lod_select.make_dropdownB(); lod_select.show_menu(lod_menuB)";

Reply all
Reply to author
Forward
0 new messages