Triggers

Base

exception NodeHasExistingCommand

Bases: Exception

exception NodeHasExistingTrigger

Bases: Exception

exception MissingRegisteredCommandOnNode

Bases: Exception

class TriggerRegistry(*args, **kwargs)

Bases: object

Singleton class which manages all trigger commands

TRIGGER_ENV = 'ZOO_TRIGGER_COMMAND_PATH'
commands()
Returns:

Return type:

dict[str, TriggerCommand]

commandTypes()
Returns:

Return type:

list[str]

command(commandName)
Parameters:

commandName (str) – the registered command unique id

Returns:

Return type:

callable[TriggerCommand] or None

commandFromNode(node)

Internal method to retrieve the command class object from the node. We don’t initialize the command as we don’t want to overhead in every query.

Parameters:

node (zapi.DGNode) – The Node to find the command class on.

Returns:

the trigger command class, this is a uninitialized class

Return type:

callable[TriggerCommand] or None

createTriggerForNode(node, commandName, modifier=None)

Creates a trigger on the node, see TriggerNode for more information.

This function is not undoable.

Parameters:
  • node (zapi.DGNode) – The node to create the trigger on

  • commandName (str) – The trigger unique identifier(id attribute).

  • modifier (zapi.dgModifier or None) – The maya om2 modifier to use if you need to handle undo(inside MPXCommands).

Returns:

the created trigger node class.

Return type:

TriggerNode

Raise:

NodeHasExistingTrigger

class TriggerNode(node)

Bases: object

This encapsulates a single nodes trigger, includes the method to execute commands/menus

TRIGGER_ATTR_NAME = 'zooTrigger'
COMMANDTYPE_ATTR_NAME = 'zooTriggerCommandType'
TRIGGER_MENU_TYPE = 0
TRIGGER_SELECTION_TYPE = 1
LAYOUT_TYPE = 0
DYNAMIC_TYPE = 1
static fromNode(node)

Cast the node to a triggerNode class.

Parameters:

node (zapi.DGNode) – The node to cast

Returns:

The triggerNode for the specified node or None if the node isn’t a triggerNode.

Return type:

TriggerNode or None

static hasTrigger(node, strict=False)

Determines if the specified node contains a trigger or connected meta nodes has a trigger.

Parameters:
  • node (zapi.DGNode) – The node to search.

  • strict (bool) – if true then only the the node will be searched not connections.

Return type:

bool

static hasCommandType(node, commandType)

Determines if the specified node has the trigger command class.

Parameters:
  • node (zapi.DGNode) – The node to search.

  • commandType (callable[TriggerCommand]) –

Returns:

True if the node has the command type

Return type:

bool

property node

Returns the node instance this trigger is associated with

Return type:

zapi.DGNode

setCommand(command, modifier=None, apply=True)

Sets the trigger command instance, with will result in trigger attributes being created.

Parameters:

command (TriggerCommand) – Command to set for this trigger Node, if a command already exists it will be replaced with the specified command.

Raise:

NodeHasExistingCommand

command()

Returns the TriggerCommand for the node or None if it doesn’t have a command yet.

Return type:

TriggerCommand

isCommandType(commandType)

Returns True if the current command is an instance of ‘commandType’ class.

Parameters:

commandType (callable[TriggerCommand]) – The commandType to check against

Return type:

bool

isCommandBaseType(baseType)
Parameters:

baseType (int) – The commandType to check against

Return type:

bool

deleteTriggers(modifier=None, apply=True)

Deletes the trigger from the node. :param modifier: The maya dg modifier to use, if None then this function isn’t undoable :type modifier: zapi.dgModifier or None :param apply: if True and a modifier is passed then doIt() will be called :type apply: bool

attributes()

Returns the list of attributes which will be added to the triggerNode, this method calls the commands attributes() function.

Returns:

list of attributes flags in the same form as zapi.DGNode.addAttribute()

Return type:

list[dict]

class TriggerCommand(trigger=None, manager=None)

Bases: Plugin

baseType = 0
id = ''
property node

Returns the node attached to this trigger command.

Return type:

zapi.DGNode

attributes()

Unique attributes for the command to be created on the node.

Returns:

a list of attribute dicts in the same form as zapi.DGNode.addAttribute()

Return type:

list[dict]

onCreate(modifier=None)

The function gets called when the command gets created on the node allowing for custom control of the command. It’s recommended to only make changes of the modifier.

Parameters:

modifier (zapi.dgModifier) – The maya modifier that all changes will be applied too.

Returns:

Return type:

execute(*args, **kwargs)
connectedTriggerNodes(nodes, filterCls=None)

Generator function that returns all triggerNodes as DGNodes within the specified nodes list or any connected meta nodes in the network.

Parameters:
  • nodes (list[zapi.DGNode]) –

  • filterCls (callable[TriggerCommand]) –

Returns:

Return type:

Generator[zapi.DGNode]

Trigger Command API (Undoable)

This Modules contains the primary undo API for triggers.

Each function simply calls the matching zooCommand

createMenuTriggers(nodes, menuId, triggerCommandId=None)

Undoable function which creates the same menu trigger every node provided.

Parameters:
  • nodes (list[zapi.DGNode]) – The list of nodes to add the trigger too.

  • menuId (str) – the layout Id or dynamic marking menu id

  • triggerCommandId (str or None) – The trigger command id to use, If none it will use the default menu.

Returns:

A list of triggerNode classes which were created.

Return type:

list[zoo.libs.maya.triggers.TriggerNode]

createSelectionTrigger(nodes, commandStr=None, connectables=None, triggerCommandId=None)

Undoable function which creates the same Selection trigger every node provided.

Parameters:
  • nodes (list[zapi.DGNode]) – The list of nodes to add the trigger too.

  • commandStr (str) – The python command string, must support exec() function

  • connectables (list[zapi.DGNode]) – Adds the list of specified nodes to the current command.

  • triggerCommandId (str or None) – The trigger command id to use, If none it will use the ‘selectConnected’.

Returns:

A list of triggerNode classes which were created.

Return type:

list[zoo.libs.maya.triggers.TriggerNode]

deleteTriggers(nodes)

Deletes the triggers on all nodes specified.

Parameters:

nodes (list[zapi.DGNode]) – The list node DGNodes to remove triggers from.

Trigger Menu command

removePrimaryMenu()
class TriggerMenuCommand(trigger=None, manager=None)

Bases: TriggerCommand

id = 'triggerMenu'
COMMAND_ATTR_NAME = 'zooTriggerMenuName'
attributes()

Unique attributes for the command to be created on the node.

Returns:

a list of attribute dicts in the same form as zapi.DGNode.addAttribute()

Return type:

list[dict]

menuId()

Returns the internal id of the marking menu layout.

Returns:

The marking menu layout id.

Return type:

str

setMenu(menuId, mod=None)

Set’s the current menu layout id for this command on the node.

Parameters:
  • menuId (str) – The marking menu layout id

  • mod (zapi.dgModifier) – The modifier to use for undo.

execute(arguments)

This method loads the marking menu layout for the command, if the layout is off dynamic then the class will be executed other the static layout will be loaded.

Parameters:

arguments (dict) – The arguments to pass to the marking menu class if this command is dynamic.

Returns:

The consolidate unsolved marking menu layout.

Return type:

markingmenu.Layout

buildTriggerMenu(parentMenu, nodeName)

Internal method to Build and display the trigger menu for the specified node by name.

Parameters:
  • parentMenu (str) – The maya parent menu name.

  • nodeName (str or None) – The initial node(under the mouse pointer), can be None we consolidate the currently selected nodes.

Returns:

If the menu was successfully built.

Return type:

bool

gatherMenusFromNodes(nodeName=None)

Internal function which gets called by buildTriggerMenu() which returns the current selected nodes and the final composed(unSolved) trigger menu layout.

Note:

This function is the one that executes the trigger commands.

Parameters:

nodeName (str or None) – The maya path to the scene node to find the initial trigger on

Returns:

Return type:

buildMenuFromSelection()

Builds and displays the marking menu for the current selected nodes.

Returns:

1 if the selected displayed a marking menu else 0.

Return type:

int

Trigger Maya Selection Command

class TriggerSelectionBase(trigger=None, manager=None)

Bases: TriggerCommand

baseType = 1
COMMAND_ATTR_NAME = 'zooTriggerCommand'
COMMAND_CONNECT_ATTR_NAME = 'zooTriggerConnects'
attributes()

Unique attributes for the command to be created on the node.

Returns:

a list of attribute dicts in the same form as zapi.DGNode.addAttribute()

Return type:

list[dict]

commandStr()

Returns the python command string which will be executed.

Return type:

str

setCommandStr(commandStr, mod=None, apply=True)

Sets the python string which will be executed each time a node is selected. Execute once per node.

Parameters:
  • commandStr (str) – The python command string, must support exec() function

  • mod (zapi.dgModifier) – The modifier to use for undo

  • apply (bool) – whether to immediately apply the change.

addNodesToConnectables(nodes, mod=None)

Adds the list of specified nodes to the current command. This nodes will be selected each time the node of the current command is selected.

Parameters:
  • nodes (list[zapi.DGNode]) – the list of DGNodes to add.

  • mod (zapi.dgModifier) – The undo modifier to use

clearNodes(mod=None)

Removes all currently connected nodes for this command.

Parameters:

mod (zapi.dgModifier) – The undo modifier to use.

connectedNodes()

Returns all the currently assigned nodes for selection(connected)

Returns:

A generator which returns each currently connected node

Return type:

generator[zapi.DGNode]

commandLocals()

Custom command locals to pass to the commandStr, only used by subclasses.

Return type:

dict[str, any]

execute()
class SelectConnectedCommand(trigger=None, manager=None)

Bases: TriggerSelectionBase

This command selects all currently connected nodes then runs the command string

id = 'selectConnected'
execute()