代码:
import maya.cmds as cmds
import maya.mel as mel
mainWindow = mel.eval('$temp=$gMainWindow')
mainWindowMenus = cmds.window(mainWindow, query = True, menuArray = True)
masterMenus = cmds.menu(mainWindowMenus[-2], query = True, itemArray = True)
masterMenusLabel = cmds.menu(mainWindowMenus[-2], query = True, label = True)
cmds.menuItem(masterMenus[-3], query = True, label = True)
cmds.menuItem(masterMenus[-3], query = True, command = True)
arnoldMenu = cmds.menu(masterMenus[-3], query = True, itemArray = True)
for x in arnoldMenu:
print cmds.menuItem(x, query = True, label = True)
print cmds.menuItem(x, query = True, command = True)
此查询Arnold主菜单的标签和命令(只要插件已加载且是右侧的第二个菜单)我的输出看起来像这样:
User Guide
<function <lambda> at 0x000001C32E797208>
Tutorials
<function <lambda> at 0x000001C32E797278>
Arnold Answers
<function <lambda> at 0x000001C32E7972E8>
Learning Scenes
<function <lambda> at 0x000001C32E797358>
None
Solid Angle
<function <lambda> at 0x000001C32E7973C8>
Mailing Lists
<function <lambda> at 0x000001C32E797438>
Support Blog
<function <lambda> at 0x000001C32E7974A8>
None
Developer Guide
<function <lambda> at 0x000001C32E797518>
Release Notes
<function <lambda> at 0x000001C32E797588>
空行是分隔符类型的menuItem,因此没有命令。那么如何通过Python运行这些命令?当我单击menuItems来运行代码时,总是收到如下错误消息:
Windows找不到'htmlfile \ shell \ open \ command'。确保正确输入名称,然后重试。
类似这样的东西:
<function callback at 0x0000021B812B24A8>
是这样的函数对象:
def hello():
print "Hello"
f = hello
现在f包含您好的函数对象:
<function hello at 0x0000019493BCE7B8>
并且可以通过使用“()”执行,因此请尝试:
f()
结果应为“ Hello”。