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
]
- 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 oncommandName (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:
- Raise:
- 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.
- 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:
- 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:
- command()¶
Returns the TriggerCommand for the node or None if it doesn’t have a command yet.
- Return type:
- 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:
- isCommandBaseType(baseType)¶
- 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
- 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:
- 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 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]
- setCommandStr(commandStr, mod=None, apply=True)¶
Sets the python string which will be executed each time a node is selected. Execute once per node.
- 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.
- execute()¶
- class SelectConnectedCommand(trigger=None, manager=None)¶
Bases:
TriggerSelectionBase
This command selects all currently connected nodes then runs the command string
- id = 'selectConnected'¶
- execute()¶