右键单击Maya中的一个货架按钮以启动另一个脚本



我想知道,当右键单击自定义的架子按钮vers左键单击时,是否可以在玛雅人中启动另一个脚本。因此,该按钮的传统左键单击将启动脚本的一个版本,但是右键单击(或其他操作(将执行脚本的不同版本。

是的。您可以做的是添加一个带有cmds.shelfButton的架子按钮,然后将弹出菜单与cmds.popupMenu一起连接弹出菜单,您可以在其中放置任意多的命令。cmds.popupMenu有一个参数button,您可以在其中指定鼠标按钮触发弹出窗口以显示。

import maya.cmds as cmds
# Put in what shelf tab to add the new button to.
shelf = "Rigging"
# Throw an error if it can't find the shelf tab.
if not cmds.shelfLayout(shelf_name, q=True, exists=True):
    raise RuntimeError("Not able to find a shelf named '{}'".format(shelf_name))
# Create a new shelf button and add it to the shelf tab.
# Include `noDefaultPopup` to support a custom menu for right-click.
new_shelf_button = cmds.shelfButton(label="My shelf button", parent=shelf, noDefaultPopup=True)
# Create a new pop-up menu and attach it to the new shelf button.
# Use `button` to specify which mouse button triggers the pop-up, in this case right-click.
popup_menu = cmds.popupMenu(parent=new_shelf_button, button=3)
# Create commands and attach it to the pop-up menu.
menu_command_1 = cmds.menuItem(label="Select meshes", sourceType="python", parent=popup_menu, command='cmds.select(cmds.ls(type="mesh"))')
menu_command_2 = cmds.menuItem(label="Select joints", sourceType="python", parent=popup_menu, command='cmds.select(cmds.ls(type="joint"))')
menu_command_3 = cmds.menuItem(label="Select all", sourceType="python", parent=popup_menu, command='cmds.select("*")')

最新更新