Named Graphs

exception NamedNodeAlreadyExists

Bases: Exception

exception NamedInputAlreadyExists

Bases: Exception

exception NamedOutputAlreadyExists

Bases: Exception

class NamedDGGraph(graphId, name, metaData, sceneNodes, inputs, outputs, primaryInputNode=None, primaryOutputNode=None)

Bases: object

This class provides a way to store and access a named graph of nodes in Maya’s Dependency Graph (DG).

Parameters:
  • graphId (str) – The name of the graph.

  • sceneNodes (dict[str, zapi.DGNode])) – A dictionary containing the node objects in the graph, with their node IDs as keys.

  • inputs (dict[str, list[zapi.Plug]]) –

  • outputs (dict[str, zapi.Plug]) –

  • primaryInputNode (zapi.DGNode) –

  • primaryOutputNode (zapi.DGNode) –

Example:

Here is an example of the raw graph data that could be used to create an instance of this class:

{'id': 'graphId',
  'nodes': [{'data': {'curveType': 3,
                      'frameRate': 24,
                      'frames': [0.0, 2.0, 5.0],
                      'inTangentAngles': [0.0, 0.0, 0.3217505543966422],
                      'inTangentWeights': [1.0, 1.0, 1.0],
                      'inTangents': [2, 8, 2],
                      'name': 'spine_M_squashCurve_animCurve',
                      'outTangentAngles': [-0.4636476090008062, 0.0, 0.0],
                      'outTangentWeights': [1.0, 1.0, 1.0],
                      'outTangents': [2, 8, 2],
                      'postInfinity': 0,
                      'preInfinity': 0,
                      'space': 2,
                      'type': 'animCurveTU',
                      'values': [0.0, -1.0, 0.0],
                      'weightTangents': False},
             'id': 'nodeId'}]}
static inputDataToGraph(graphNodes, inputs)

Convert input data to graph format.

Parameters:
  • graphNodes (dict[str, zapi.DGNode]) – A dictionary of graph nodes.

  • inputs (dict[str, list[str]]) – A dictionary of input data, where key is the name of the input and value is the path to the node attribute.

Returns:

A dictionary of input data in graph format, where key is the name of the input and value is the value of the node attribute.

Return type:

dict

static outputDataToGraph(graphNodes, outputs)

Convert output data to graph format.

Parameters:
  • graphNodes (dict[str, zapi.DGNode]) – A dictionary of graph nodes.

  • outputs (dict[str, str]) – A dictionary of output data, where key is the name of the output and value is the path to the node attribute.

Returns:

A dictionary of output data in graph format, where key is the name of the output and value is the value of the node attribute.

Return type:

dict

classmethod create(namedGraphData)

Class method that creates a new NamedDGGraph instance from raw graph data.

Parameters:

namedGraphData (zoo.libs.hive.base.definition.NamedGraph) – The raw graph data.

Returns:

A new NamedDGGraph instance created from the raw data.

Return type:

NamedDGGraph

graphId()

Returns the Graph instance unique identifier.

Return type:

str

setGraphId(newId)
name()

Returns the name of the graph.

Returns:

The name of the graph.

Return type:

str

rename(name)

Renames the graph.

Parameters:

name (str) – The new name for the graph.

version()

Returns the version number of this graph instance. i.e. 1.0.0.

Return type:

str

metaData()

Returns the metaData dict for this graph.

Return type:

dict

clearNodes()

Clears the current graph of nodes without deleting the nodes.

clearInputs()

Clears the current graph of inputs.

clearOutputs()

Clears the current graph of outputs.

hasNode(node)
node(nodeId)

Returns the node in the graph with the given ID.

Parameters:

nodeId (str) – The ID of the node to retrieve.

Returns:

The node with the given ID, or None if no such node exists.

Return type:

zapi.DGNode or None

nodes()

Returns the dictionary of nodes in the graph.

Returns:

The dictionary of nodes in the graph, with their node IDs as keys.

Return type:

dict[str, zapi.DGNode]

hasPrimaryInputNode()

Check if the graph has a primary input node.

Returns:

True if the primary input node exists, False otherwise.

Return type:

bool

hasPrimaryOutputNode()

Check if the graph has a primary output node.

Returns:

True if the primary output node exists, False otherwise.

Return type:

bool

primaryInputNode()

Get the primary input node of the graph.

Returns:

The primary input node of the graph.

Return type:

zapi.DGNode

primaryOutputNode()

Get the primary output node of the graph.

Returns:

The primary output node of the graph.

Return type:

zapi.DGNode

createIONodes()

Create input and output nodes for the graph and connects these input and output nodes into the graph.

delete(modifier=None)
deleteIONodes(modifier=None)

Deletes input and output nodes.

addNode(nodeId, node)

Add a node to the graph.

Parameters:
  • nodeId (str) – The identifier of the node.

  • node (zapi.DGNode) – The node to be added.

addInput(inputId, plug)

Add an input to the graph.

Parameters:
  • inputId (str) – The identifier of the input.

  • plug (zapi.Plug or list[zapi.Plug]) – The input to be added.

renameInput(inputId, newName)
renameOutput(outputId, newName)
addOutput(outputId, plug)

Add an output to the graph.

Parameters:
  • outputId (str) – The identifier of the output.

  • plug (zapi.Plug) – The output to be added.

findNodes(*nodeIds)

Returns a list of nodes in the graph with the given IDs.

Parameters:

nodeIds (str) – The IDs of the nodes to retrieve.

Returns:

A list of nodes with the given IDs, in the same order as the IDs. If a node with a given ID does not exist, the corresponding list element will be None.

Return type:

list[zapi.DGNode or None]

inputs()

Returns a dictionary of inputs, with the key being the name and value being the input plug object. If a primary input node exists, it also includes attributes that exist on the primary input node.

Returns:

dictionary of inputs

Return type:

dict

outputs()

Returns a dictionary of outputs, with the key being the name and value being the output plug object. If a primary output node exists, it also includes attributes that exist on the primary output node.

Returns:

dictionary of outputs

Return type:

dict

inputAttr(inputId)

Get the attribute of an input.

Parameters:

inputId (str) – The identifier of the input attribute.

Returns:

The attribute of the input. If the primary input node exists, it returns the attribute on the primary input node. If not it returns the input plug object.

Return type:

list[zapi.Plug]

outputAttr(outputId)

Get the attribute of an output.

Parameters:

outputId (str) – The identifier of the output attribute.

Returns:

The attribute of the output. If the primary output node exists, it returns the attribute on the primary output node. If not it returns the output plug object.

Return type:

zapi.Plug

setInputAttr(inputId, value)
connectToInput(inputId, source)
connectFromOutput(outputId, destinations)
serializeIO()

Serialize the inputs and outputs of the graph.

Returns:

A dictionary with the keys “inputs” and “outputs” containing the serialized inputs and outputs respectively.

Return type:

dict

externalConnections()
serialize()

Returns a serialized representation of the graph.

Returns:

A serialized representation of the graph.

Return type:

dict

createNamedGraph(layer, namedGraphData, track=True, createIONodes=False)

Creates a Maya DG graph from the provided NamedGraph instance.

Parameters:
  • layer (zoo.libs.hive.base.hivenodes.HiveLayer) – The Hive Layer to create the graph on, currently only support Guide and rig layer.

  • namedGraphData (zoo.libs.hive.base.definition.NamedGraph) –

  • track (bool) – Whether this graph will be tracked as meta-data on the provided layer

  • createIONodes (bool) – Whether to create the input and output DG nodes for this graph.

Returns:

Returns the newly created graph instance.

Return type:

NamedDGGraph

hasNamedGraph(layer, graphName)

Determines if the given graph exists on the layer given the name,

Parameters:
  • layer (zoo.libs.hive.base.hivenodes.HiveLayer) – The hive layer instance to search on.

  • graphName (str) – The graph name to filter by.

Return type:

bool

namedGraph(layer, graphName, graphRegistry)

Retrieve the named graph on the given layer based on its name.

Parameters:
  • layer (zoo.libs.hive.base.hivenodes.HiveLayer) – The hive layer instance to search on.

  • graphName (str) – The graph name to filter by.

  • graphRegistry (zoo.libs.hive.base.registry.GraphRegistry) – The registry instance to look for the graph.

Returns:

The named graph if it exists, otherwise None.

Return type:

zoo.libs.hive.base.serialization.NamedDGGraph or None

namedGraphs(layer, graphRegistry)

Returns all NamedGraphs on the given layer.

Parameters:
Return type:

list[zoo.libs.hive.base.serialization.NamedDGGraph]

findNamedGraphs(layer, graphRegistry, names)

Returns all NamedGraphs on the given layer with the provided names.

Parameters:
  • layer (zoo.libs.hive.base.hivenodes.HiveLayer) – The hive layer instance to search on.

  • graphRegistry (zoo.libs.hive.base.registry.GraphRegistry) – The registry instance to look for the graph.

  • names (list[str]) – A list of graph names to retrieve graph instances for.

Return type:

list[zoo.libs.hive.base.serialization.NamedDGGraph or None]

deleteNamedGraph(layer, graphName, graphRegistry, modifier=None)

Deletes the NamedGraph if found by its name.

Parameters:
  • layer (zoo.libs.hive.base.hivenodes.HiveLayer) – The hive layer instance to search on.

  • graphName (str) – The graph name to filter by.

  • graphRegistry (zoo.libs.hive.base.registry.GraphRegistry) – The registry instance to look for the graph.

  • modifier (zapi.dagModifier or None) – The maya dagModifier to use for deletion.