【发布时间】: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。并将其用作父母