右键单击 Maya 中的架子按钮以启动不同的脚本
right click a shelf button in Maya to launch a different script
我想知道在自定义工具架按钮上单击鼠标右键与单击鼠标左键时是否可以在 Maya 中启动不同的脚本。因此,传统的左键单击按钮会启动一个版本的脚本,但右键单击(或其他一些操作)会执行不同版本的脚本。
是的,这是可能的。您可以做的是添加一个带 cmds.shelfButton
的搁架按钮,然后附加一个带 cmds.popupMenu
的 pop-up 菜单,您可以在其中放置任意数量的命令。 cmds.popupMenu
有一个参数 button
,您可以在其中指定触发 pop-up 显示的鼠标按钮。
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("*")')
我想知道在自定义工具架按钮上单击鼠标右键与单击鼠标左键时是否可以在 Maya 中启动不同的脚本。因此,传统的左键单击按钮会启动一个版本的脚本,但右键单击(或其他一些操作)会执行不同版本的脚本。
是的,这是可能的。您可以做的是添加一个带 cmds.shelfButton
的搁架按钮,然后附加一个带 cmds.popupMenu
的 pop-up 菜单,您可以在其中放置任意数量的命令。 cmds.popupMenu
有一个参数 button
,您可以在其中指定触发 pop-up 显示的鼠标按钮。
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("*")')