Re: [Maya-Python] Pymel Menu won't autoload Maya 2024

255 views
Skip to first unread message
Message has been deleted

Justin Israel

unread,
May 18, 2023, 7:01:39 PM5/18/23
to python_in...@googlegroups.com


On Thu, May 18, 2023 at 5:46 AM A <alim...@gmail.com> wrote:
Hey Folks,

I have pymel, installed via pip on Maya 2024, 

Pymel itself is working. But im having a really strange issue.

My studio menu is built with pymel...

I have a maya module..  
ib.mod - this then loads the plugin 
pipeline_module.py - very simple script for making a maya module / plugin

pipeline_module.py imports a maya file called pipeline_menu.py "My maya top bar menu"

this menu just holds all my tools etc. 

The module wont load via Maya's GUI "Plugin Manager" "just like you would load vray kind of setup.
This worked in Maya 2018 right through to 2023.
I need to run manually in the python interpreter "import pymel.core as pm"
This might sound simple but both the pipeline_module.py and pipeline.py files run import pymel.core as pm right at the top of both scripts.

Why am I now needing to run this before the module will load? 
The error points to menuOBJ

Error Messages...
'''
// Error: file: C:/Program Files/Autodesk/Maya2024/scripts/others/pluginWin.mel line 316: RuntimeError: file C:\Program Files\Autodesk\Maya2024\Python\lib\site-packages\pymel\internal\pmcmds.py line 217: menu: Object 'menuOBJ' not found.
// Warning: file: C:/Program Files/Autodesk/Maya2024/scripts/others/pluginWin.mel line 316: Failed to run file: C:/Users/Alistair Messom/IB/maya_pipeline/mod/plug-ins/pipeline_module.py
// Error: file: C:/Program Files/Autodesk/Maya2024/scripts/others/pluginWin.mel line 316:  (pipeline_module)
'''

My pipeline_menu.py script... well the top of it, the only part that calls or refers to menuOBJ is the string in variable menu_obj = 'menuOBJ'

The error you reported indicates that it comes from the call to 
pm.menu(menu_obj, e=True)
where for whatever reason it thinks the 'menuOBJ' menu does not exist.  
Seeing as the label and parent keyword arguments are being ignored in your first check for existence, could you not just simplify the whole thing with an exception handler?
try:
    found = pm.menu(menu_obj, e=True)
except RuntimeError:
    pass
else:
    pm.deleteUI(found)

That aside, I don't know why the 'exists' check would succeed, but then it fails to find the menu object afterwards.

'''
"""
PIPELINE MENU
"""
import maya.cmds as cmds
import pymel.core as pm
import os

company_name = (
os.environ['CUSTOM_PIPELINE_NAME'])

def make_the_menu():

main_window = pm.language.melGlobals[
'gMainWindow']
menu_obj = 'menuOBJ'
menu_label = company_name

if pm.menu(
menu_obj,
label=menu_label,
exists=True,
parent=main_window):
pm.deleteUI(pm.menu(menu_obj, e=True))
'''
Please not if I manually run "import pymel.core as pm"

Then activate the module with Maya's GUI "plugin Manager" it opens / works fine.
Are we looking at a bug here? 
I just don't get it!!

Thanks,


--
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/1ade785e-46dd-4181-a2de-aab73c5e6527n%40googlegroups.com.

Marcus Ottosson

unread,
May 19, 2023, 3:12:07 AM5/19/23
to python_in...@googlegroups.com

Could it be a problem of your script running before Maya is initialised?

If you cmds.evalDeferred(make_the_menu) then that would let Maya do its dance before your script kicks in.


Alistair

unread,
May 19, 2023, 8:18:34 AM5/19/23
to Python Programming for Autodesk Maya
Hey Guys, 

Thanks for the help here,

I have tried both of your solutions.. I have it working now with Justins' advice..
Marcus, I did try you're 'cmds.evalDeferred(make_the_menu)' suggestion but this didn't resolve the issue - Just stating for others are aware of the solution. 

I'm not 100% sure why it is working now but it is! Quite odd I haven't had any issues with previous versions of Maya, but 2024 brought the issue up. 
Does pymel load differently now? I know it needs pip installing.. but I assumed once installed would just work the same as before.
Apologies for my ignorance on this.. The menu plugin / module side of things was created without a great deal of understanding, "Just following online tut's / examples'

Below is the fix... my old method is now commented out and Justins exeption handler added as a replacement.
'''
def make_the_menu():

main_window = pm.language.melGlobals[
'gMainWindow']
menu_obj = 'menuOBJ'
menu_label = company_name

'''
# OLD WAY OF LOADING BEDFORE MAYA 2024 HAPPENED


if pm.menu(
menu_obj,
label=menu_label,
exists=True,
parent=main_window):
pm.deleteUI(pm.menu(menu_obj, e=True))
'''

try:
    found = pm.menu(menu_obj, e=True)
except RuntimeError:
    pass
else:
    pm.deleteUI(found)
'''
 Thanks a lot!!

Reply all
Reply to author
Forward
0 new messages