Dependency graph plug-ins

This section introduces the Dependency Graph (DG), and shows how to use the Maya API to write plug-ins that extend and integrate with it.

The dependency graph lies at the heart of Maya. It maintains the construction history of the scene: a record of what operations you have applied in what order. The graph is made up of a series of interconnected nodes, each of which encapsulates a single operation or a single set of calculations. Each node accepts a limited set of well-defined input data, performs its calculations based on that data, and produces one or more output values. For more background information about nodes, connections, and how the dependency graph works, see About the dependency graph.

You can use the Maya API to create your own custom dependency graph nodes, which carry out custom operations based on their incoming data. Each kind of node you write is represented by a class that derives from the base MPxNode class, which provides the main interface needed in order to hook up to the dependency graph. The Maya API also provides several other base classes that derive from MPxNode, but that specialize its behavior for different uses. For example, you can derive your custom node class from MPxDeformerNode instead of MPxNode in order to implement a custom deformer. Maya will treat your custom node in the same way that it treats built-in types of deformers. For a description of these base classes, see Base dependency node classes.

Every node class needs to be set up with some attributes, which define the types of input data the node accepts and the types of output data that the node produces. For more information, see Attributes and plugs and Complex and Dynamic Attributes.

The main work done by each dependency graph node is typically done in its virtual compute() method, which you must implement in your custom class. For considerations to keep in mind when writing your implementation, see Implementing the compute() method for a dependency graph node. Maya maintains all data related to each node in a dedicated data block, which it passes to this method each time an output value for the node needs to be re-computed. You need to use handles to read the input data from this block, and to write the output data to the block. For details, see Working with data blocks.

For working examples of plug-ins that define new types of dependency graph nodes, see A basic dependency node example and A more complex dependency graph example.

  • A basic dependency node example

    The following example demonstrates a simple custom dependency graph node that derives from the base MPxNode parent class. It takes a single floating-point number as input, computes the sine of the number, and outputs the result.

  • About the dependency graph

    This page provides a brief description of how the dependency graph works.

  • Base dependency node classes

    In order for you to write a custom dependency graph node, you must create a new class that derives from one of the base node classes described on this page. Depending on the purpose of the node you want to create, you can choose any of these options as your starting point.

  • Attributes and plugs

    This page describes how to work with simple, static attributes and plugs.

  • Complex and Dynamic Attributes

    In addition to the simple, static attributes described in Attributes and plugs, your custom node classes can use complex attributes made up of multiple data values. These may be arrays that contain multiple instances of the same data type, or they may be compounds that are made up of multiple different data types. In addition, you can use dynamic attributes to add and remove attributes from nodes on the fly.

  • Implementing the compute() method for a dependency graph node

    This topic provides some principles to keep in mind when implementing the virtual MPxNode::compute() method for a custom dependency node class.

  • Working with data blocks

    When Maya calls the compute() method for a dependency graph node, it passes along an MDataBlock object that stores the values of all input and output attributes. This page describes how your implementation of MPxNode::compute() can read and write attribute values in this data block.

  • A more complex dependency graph example

    This page provides a slightly more complex example of a dependency graph node plugin.

  • Evaluation using current context