右键单击Maya中的书架按钮以启动其他脚本

时间:2019-05-18 18:06:27

标签: python maya

我想知道,在自定义书架按钮上单击鼠标右键与左键单击时,是否可以在Maya中启动其他脚本。因此,传统的左键单击将启动该脚本的一个版本,但是右键单击(或其他操作)将执行该脚本的另一个版本。

1 个答案:

答案 0 :(得分:1)

是的,有可能。您可以做的是添加带有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("*")')
相关问题