1 import maya.cmds
as cmds
2 import maya.api.OpenMaya
as om
4 PLUGIN_NAME =
"demoSequencerCustomMenuCallbacks"
8 Get the total number of shots in the sequencer
10 shots = cmds.ls(type=
"shot")
13 def demo_top_menu_callback(editor):
15 Function to add a custom menu to the sequencer UI.
16 This function will be called by Maya when building the sequencer's top menu.
17 This example adds a menu item that displays the total shot count when selected.
19 editor (str): The name of the Sequencer editor where the menu is being built.
21 print(
"Adding custom menu to editor: {}".format(editor))
22 cmds.menu(label=
"Demo Menu")
23 cmds.menuItem(label=
"Shot Count", command=
lambda *args: om.MGlobal.displayInfo(
"Total Shots: {}".format(shot_count())))
25 def demo_toolbar_buttons_callback(editor):
27 Function to add custom toolbar buttons to the sequencer UI.
28 This function will be called by Maya when building the sequencer's toolbar.
29 This example adds a button that displays the total shot count when clicked.
31 editor (str): The name of the Sequencer editor where the toolbar is being built.
33 print(
"Adding custom toolbar buttons to editor: {}".format(editor))
34 cmds.separator(style=
"toolbar", horizontal=
False, height=20)
35 cmds.iconTextButton(ann=
"Shot Count", label=
"Shot Count", image1=
"item_add.png", command=
lambda *args: om.MGlobal.displayInfo(
"Total Shots: {}".format(shot_count())))
37 def demo_context_menu_callback(editor, parent_menu, context, id, track_type):
39 Function to add custom right-click menu items to shots in the sequencer.
40 This function will be called by Maya when building the context menu for shots in the sequencer.
41 This example adds a menu item that displays information about the context of the menu.
43 editor (str): The name of the Sequencer editor where the context menu is being built.
44 parent_menu (str): The parent context menu to which new menu items should be added.
45 context (str): The context in which the right-click occurred. See cameraSequencer menuContext flag documentation. Possible values include:
46 - "timeSlider": Right-clicked on the time slider.
47 - "nothing": Right-clicked outside of any specific UI element.
48 - "clip": Right-clicked on a clip.
49 - "audio": Right-clicked on an audio element.
50 - "track": Right-clicked on a track.
51 id (str): The identifier of the item under the cursor (e.g., clip name or track index), if applicable.
52 track_type (str): The type of track if in a track context. Can be "audio" or empty, indicating a sequence track.
54 cmds.setParent(parent_menu, menu=
True)
55 cmds.menuItem(divider=
True)
62 message =
"Right-clicked on Time Slider"
64 message =
"Outside of any specific UI element"
66 message = f
"Right-clicked on the clip: {id}"
68 message = f
"Right-clicked on the audio: {id}"
70 track_type_label =
"audio" if track_type ==
"audio" else "sequence"
71 message = f
"Right-clicked on {track_type_label} track number {id}"
73 cmds.menuItem(label=message, enable=
False)
75 def register_ui_callbacks():
77 Register UI callbacks using Maya's callbacks command.
78 This function will be called when the plugin is initialized to ensure that
79 the custom menus and toolbar buttons are added to the sequencer UI.
80 Each callback is associated with a specific hook that Maya will call at the
81 appropriate time when building the sequencer UI.
82 The owner parameter is used to group callbacks together, allowing for easy
83 removal when the plugin is uninitialized.
86 cmds.callbacks(addCallback=demo_top_menu_callback,
87 hook=
"sequencerAddMenus",
91 cmds.callbacks(addCallback=demo_toolbar_buttons_callback,
92 hook=
"sequencerAddToolButtons",
96 cmds.callbacks(addCallback=demo_context_menu_callback,
97 hook=
"sequencerAddRMBMenuItems",
100 def clear_ui_callbacks():
102 Clear all callbacks registered by this plugin.
103 This function will be called when the plugin is uninitialized but the
104 sequencer must be reopened before the added UI elements are removed.
106 cmds.callbacks(clearCallbacks=
True, owner=PLUGIN_NAME)
108 def initializePlugin(mobject):
110 register_ui_callbacks()
111 except Exception
as e:
112 om.MGlobal.displayError(
"Failed to register plugin: " + str(e))
115 def uninitializePlugin(mobject):
118 except Exception
as e:
119 om.MGlobal.displayError(
"Failed to uninitialize plugin: " + str(e))
121 if __name__ ==
'__main__':
122 register_ui_callbacks()