щелкните правой кнопкой мыши кнопку полки в Maya, чтобы запустить другой скрипт - PullRequest
0 голосов
/ 18 мая 2019

Мне было интересно, можно ли запустить другой скрипт в Maya, когда щелчок правой кнопкой мыши на пользовательской кнопке полки превращает щелчок левой кнопкой мыши. Таким образом, традиционный щелчок левой кнопкой мыши запускает одну версию скрипта, но щелчок правой кнопкой мыши (или какое-либо другое действие) запускает другую версию скрипта.

1 Ответ

1 голос
/ 21 мая 2019

Да, это возможно.Что вы можете сделать, это добавить кнопку полки с 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("*")')
...