【问题标题】:Maya – Custom menu is not showing on menu barMaya – 自定义菜单未显示在菜单栏上
【发布时间】:2021-11-24 16:10:25
【问题描述】:

我正在尝试在 Maya 中构建自定义菜单。

google groups 有这个代码,它显示它可以工作,但是当我尝试它时它没有显示在我的菜单栏中。我已经尝试了几个小时。它还需要什么才能显示在菜单中。 IOW 为什么它不显示在 Maya 菜单栏中。

https://groups.google.com/g/python_inside_maya/c/XqM7Rkm2kOE

import pymel.core as pm

# Name of the global variable for the Maya window
MainMayaWindow = pm.language.melGlobals['gMainWindow'] 

# Build a menu and parent underthe Maya Window
customMenu = pm.menu('Custom Menu', parent=MainMayaWindow)
# Build a menu item and parent under the 'customMenu'
pm.menuItem(label="menu item 'hihi'", command="print 'hihi'", parent=customMenu)

编辑: 查询菜单时,它会在列表中显示它

maya_main_window = mel.eval("$tmpVar = $gMainWindow")

menus = cmds.window(maya_main_window, query=True, menuArray=True)
for menu in menus:
    print menu

【问题讨论】:

  • 该链接中的帖子已经有将近 7 年的历史了,从那时起可能已经发生了很多变化。我建议找到最新的东西,看看是否有帮助。
  • @RandomDavis,我的意思是我从谷歌搜索中尝试的每件事都没有显示在菜单栏上。然而,在脚本编辑器中查询所有菜单有这个自定义菜单(见上面的编辑)
  • 您需要将菜单作为 menuBar 的父级,而不是窗口。于是得到MainMayaWindow的menuBar。并将其用作父母

标签: python maya


【解决方案1】:

有效

我正在使用在 macOS Monterey 上运行的 Maya 2020。您的代码工作正常。截图如下:

import pymel.core as pm

MainMayaWindow = pm.language.melGlobals['gMainWindow']
customMenu = pm.menu('Custom Menu', parent=MainMayaWindow)
pm.menuItem(l="menu item 'hihi'", command="print 'hihi'", parent=customMenu)

如果它不起作用

如果您无法创建该菜单,问题是您的模块可能已损坏。我认为你能做的最好的两件事就是重新安装它,或者只使用maya.cmds而不是PyMelOpenMaya

不使用 PyMel 的主要原因——因为它太慢了。不使用 OpenMaya 的主要原因——因为有太多样板代码。观看this video 了解 PyMel 模块的优缺点。

【讨论】:

  • 谢谢@Andy Jazz。不是很明显,但窗口已经出现在工作区选项后面的某个地方。
猜你喜欢
  • 2018-11-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多