This command allows you to add callbacks at key times during UI creation so that the Maya UI can be extended. The list of standard Maya hooks, as well as the arguments which will be passed to the callback based on the context are enumerated in the describeHookssection below. Custom hooks can also be added if third parties want to add UI extensibility to their plugins.
Long name (short name) | Argument Types | Properties | |
---|---|---|---|
addCallback (ac) | script | ||
|
|||
clearAllCallbacks (cac) | bool | ||
Clear all the callbacks for all hooks and owners. This is generally only used during plugin development and testing as it affects all callbacks registered by Maya and other third parties. |
|||
clearCallbacks (cc) | bool | ||
|
|||
describeHooks (dh) | bool | ||
List the standard Maya hooks. Below is a list of the hooks and their associated arguments and return values. Custom hooks added by third parties are not listed. hyperShadePanelBuildCreateMenuThis hook is called to add content to the Hypershade panel create menu. It will be called after the standard Maya node entries have been created. This callback does not have any arguments or return values. In order to preserve the desired look in the Maya UI, these callbacks should add a menu item divider just before returning using: menuItem -divider true.hyperShadePanelBuildCreateSubMenuThis hook is called to get a classification string for the custom renderer shading nodes, to prevent them from being listed with the standard Maya nodes. This callback does not have any arguments. returns: a classification string, such as rendernode/myrendererhyperShadePanelPluginChangeThis hook is called when a plugin change event (loading / unloading) has occurred to inform Maya whether the Hypershade panel needs to be rebuilt. classification (string): classification string belonging to a plugin node, possibly from another pluginchangeType (string): either loadPluginor unloadPluginreturns: (int) non-zero if your plugin is responsible for nodes of this classification, and a Hypershade rebuild is requiredcreateRenderNodeSelectNodeCategoriesThis hook is called when the Create Render Node dialog is being constructed, and allows a third party to have their nodes selected by default. A flag of the form -allWithMyRendererUpis the standard form, and the selection can be set up in the tree lister in the callback. There is no return value for this callback. flag (string): flag passed to the Create Render Node dialog command with the leading minus (-) removedtreeLister (string): the tree lister widget which should be affectedFor example, your callback might look like: global proc myRendererCreateRenderNodeSelectNodeCategoriesCallback(string $flag, string $treeLister){ if($flag == “allWithMyRendererUp”) { treeLister -e -selectPath “myrenderer” $treeLister; } } createRenderNodePluginChangeThis hook is called when a plugin change event has occurred to decide if the Create Render Node dialog needs to be closed. classification (string): classification string belonging to a plugin node, possibly from another pluginreturns: (int) non- zero if your plugin is responsible for nodes of this classification, and the Create Render Node dialog needs to be closedrenderNodeClassificationThis hook is called to get a classification string for the custom renderer shading nodes. This is used to determine if a given node type belongs to a plugin renderer. This callback does not have any arguments. returns: a classification string, such as rendernode/myrenderercreateRenderNodeCommandThis hook is called to give plugin renderers the chance to register their own command for creating their nodes from the render node treeLister and Node Editor. The callback should determine from the classification of the node type in question if it is theirs, and if so, return the appropriate command for creating new nodes of that type. postCommand (string): command to be run after the create commandtype (string): nodeTypereturns: (string) MEL create commandbuildRenderNodeTreeListerContentThis hook is called to give plugin renderers the chance to add their content to the render node tree lister. renderNodeTreeLister (string): the render node tree listerpostCommand (string): command to be run post-creationfilterString (string): a space delimited list of filtersAETemplateCustomContentThis hook is called to give plugins a chance to add content to the Attribute Editor for nodes which source AEdependNodeTemplate. nodeName (string): the name of the node for which the Attribute Editor is being constructedfirstConnectedShaderThis hook is called to determine the primary custom shader connected to the given Shading Engine. nodeName (string): the name of the Shading Enginereturns (string): the name of the custom shader if applicableallConnectedShadersThis hook is called to determine all the shaders connected to the given Shading Engine. nodeName (string): the name of the Shading Enginereturns (string): A colon separated list of the connected custom shaders (shader1:shader2:shader3)renderLayerPresetMenuThis hook is called to give plugins a chance to add presets to a renderLayer node. nodeName (string): the name of the renderLayer nodeaddBakingMenuItemsThis hook is called to give plugins a chance to add baking menu items to the global Render - Lighting/Shading menu. menuItemAnchor (string): the name of the menuItem which the new baking menu items should be inserted after.addVertexBakingMenuItemsThis hook is called to give plugins a chance to add baking menu items to the global Polygon - Color menu.addPrelightMenuItemsThis hook is called to give plugins a chance to add pre-lighting menu items to the global Polygon - Color Set Editor menu.addRMBBakingMenuItemsThis hook is called to give plugins a chance to add baking menu items to the RMB menu. objectName (string): The name of the object the right mouse button event occured on.addMayaRenderingPreferencesThis hook is called to give plugins a chance to add custom preferences to the Maya’s Rendering Preferences section.updateMayaRenderingPreferencesThis hook is called to give plugins a chance to update custom preferences of the Maya’s Rendering Preferences section.addMayaMuscleMenuItemsThis hook is called to give plugins a chance to add menu items to the Maya muscle Displace menu. menuItemAnchor (string): the name of the menuItem which the new Maya muscle menu items should be inserted after.addMayaMuscleShelfButtonsThis hook is called to give plugins a chance to add items to the Maya muscle shelves.addBackburnerRendererMenuItemsThis hook is called to give plugins a chance to add items to Maya’s Backburner list of available renderers. Note: The menuItem added must be named with the short name equivalent of the renderer. eg: The Maya software renderer adds a menuItem named ‘sw’.Flag can appear in Create mode of commandFlag can have multiple arguments, passed either as a tuple or a list. |
|||
dumpCallbacks (dc) | bool | ||
|
|||
executeCallbacks (ec) | bool | ||
Execute the callbacks for the specified hook, passing the extra arguments to each callback when it is executed. Returns an array (MEL) or list (Python) containing the return values from each callback that was executed. If a callback returns no value, the array will contain an empty string (MEL) or None (Python). |
|||
hook (h) | unicode | ||
|
|||
listCallbacks (lc) | bool | ||
|
|||
owner (o) | unicode | ||
|
|||
removeCallback (rc) | script | ||
|
Derived from mel command maya.cmds.callbacks
Example:
import pymel.core as pm
import maya.cmds as cmds
def myCallbackFunction(arg1, arg2):
return arg1 + arg2
# add a new callback for myPlugin to be called when creating the attribute editor UI
pm.callbacks(addCallback=myCallbackFunction, hook='desiredHook', owner='myPlugin')
# remove an individual callback
pm.callbacks(removeCallback=myCallbackFunction, hook='desiredHook', owner='myPlugin')
# remove all callbacks for myPlugin for a specified hook
pm.callbacks(clearCallbacks=True, hook='desiredHook', owner='myPlugin')
# remove all callbacks for myPlugin for all hooks
pm.callbacks(clearCallbacks=True, owner='myPlugin')
# list callbacks for a specified hook
callbacks = pm.callbacks(listCallbacks=True, hook='desiredHook')
# list callbacks for a specified hook and for a specified owner
callbacks = pm.callbacks(listCallbacks=True, hook='desiredHook', owner='myPlugin')
# get a list of the standard Maya hooks
pm.callbacks(describeHooks=True)
# Result: [u'hyperShadePanelBuildCreateMenu', u'hyperShadePanelBuildCreateSubMenu', u'hyperShadePanelPluginChange', u'createRenderNodeSelectNodeCategories', u'createRenderNodePluginChange', u'renderNodeClassification', u'createRenderNodeCommand', u'buildRenderNodeTreeListerContent', u'AETemplateCustomContent', u'firstConnectedShader', u'allConnectedShaders', u'renderLayerPresetMenu', u'addBakingMenuItems', u'addVertexBakingMenuItems', u'addPrelightMenuItems', u'addRMBBakingMenuItems', u'addMayaRenderingPreferences', u'updateMayaRenderingPreferences', u'addMayaMuscleShelfButtons', u'addMayaMuscleMenuItems', u'addBackburnerRendererMenuItems'] #
# execute the callbacks for the hook 'desiredHook'
results = pm.callbacks('arg1', 'arg2', executeCallbacks=True, hook='desiredHook')