- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Examples

- Class List
- Class Hierarchy
- Class Members

Public Member Functions | Static Public Member Functions

# MAttributePattern Class Reference
OpenMaya - API module for common classes

This reference page is linked to from the following overview topics: Autodesk Maya 2013.

Search for all occurrences

## Detailed Description

The pattern of an attribute tree that can be applied to nodes or node classes.

Class that provides a pattern of attributes to be applied to nodes as dynamic attributes or to node classes as extension attributes.

An attribute pattern is a pattern describing an attribute tree. In the simplest implementation it can just store an internal copy of the tree to be applied. The code to apply the attribute patterns will use the rootAttr() and rootAttrCount() methods to iterate through the list of top level attributes to be applied. It presumes that if they are compounds then their children will already be parented properly.

        for( unsigned int i=0; i < tmpl.rootAttrCount(); ++i )
        {
            applyAttributesToNodes( tmpl.rootAttr(i), someNode );
        }

When creating the pattern from inside MPxAttributePatternFactory you add only the root level attributes, i.e. the attributes without parents. As a simple example if your pattern factory has data that specifies creating a pattern with one integer attribute and one compound with three float children the code would like something like this.

        MStatus status;

        MFnCompoundAttribute parentAttr;
        MObject parentObj1 = parentAttr.create( "parent", "par", &status );

        MFnNumericAttribute childAttrX;
        MFnNumericAttribute childAttrY;
        MFnNumericAttribute childAttrZ;
        MObject childObjX = childAttrX.create( "childX", "cx" MFnNumericData::kFloat, 0, &status );
        MObject childObjY = childAttrY.create( "childY", "cy" MFnNumericData::kFloat, 0, &status );
        MObject childObjZ = childAttrZ.create( "childZ", "cz" MFnNumericData::kFloat, 0, &status );
        parentAttr.addChild( childObjX );
        parentAttr.addChild( childObjY );
        parentAttr.addChild( childObjZ );

        MFnNumericAttribute otherParent;
        MObject parentObj2 = otherParent.create( "intValue", "iv" MFnNumericData::kInt, 0, &status );

        // Note that you only add the top-level attributes to the pattern,
        // not the children.
        MAttributePattern* tmpl = new MAttributePattern("myPattern");
        return ( (tmpl->addRootAttr( parentObj1 ) == MS::kSuccess)
            &&   (tmpl->addRootAttr( parentObj2 ) == MS::kSuccess) );

`#include <MAttributePattern.h>`

List of all members.

## Public Member Functions
| MAttributePattern ()
| Default MAttributePattern object has no internal Maya object.
| MAttributePattern (const MString &name)
| Construct an MAttributePattern object with the given name.
| MAttributePattern (const MAttributePattern &rhs)
| Construct an MAttributePattern object from another pattern.
MAttributePattern & | operator= (const MAttributePattern &rhs)
| Copy an MAttributePattern object from another pattern.
bool | operator== (const MAttributePattern &rhs) const
| Determine equality between two attribute patterns.
| ~MAttributePattern ()
| Destructor, doesn't do much.
MString | name (MStatus *ReturnStatus=NULL) const
| Get the name of this pattern.
unsigned int | rootAttrCount (MStatus *ReturnStatus=NULL) const
| Get the number of top level attributes present in this pattern.
MObject | rootAttr (unsigned int idx, MStatus *ReturnStatus=NULL) const
| Get a single root-level attribute from this pattern.
MStatus | removeRootAttr (unsigned int idx)
| Remove a single root attribute and its children from the pattern by index.
MStatus | removeRootAttr (const MObject &attr)
| Remove a single root attribute and its children from the pattern by attribute.
MStatus | addRootAttr (const MObject &attr)
| Add a new root attribute to the pattern.
## Static Public Member Functions
static MAttributePattern * | findPattern (const MString &name)
| Look up an existing pattern by name.
static unsigned int | attrPatternCount ()
| Get the number of patterns currently known.
static MAttributePattern * | attrPattern (unsigned int n)
| Look up an existing pattern by index value.
static const char * | className ()
| Returns the name of this class.

## Constructor & Destructor Documentation

MAttributePattern | ( | const MString & | name | ) |

Construct an MAttributePattern object with the given name.

It can then be populated with the information required for it to be able to appy a set of attributes to a node or node class.

Parameters:

  [in] | name | Name of the pattern

MAttributePattern | ( | const MAttributePattern & | rhs | ) |

Construct an MAttributePattern object from another pattern.

The internal Maya object is shared between the two MAttributePatterns.

Parameters:

  [in] | rhs | Pattern to be copied

## Member Function Documentation

MAttributePattern & operator= | ( | const MAttributePattern & | rhs | ) |

Copy an MAttributePattern object from another pattern.

Parameters:

  [in] | rhs | Pattern to be copied

bool operator== | ( | const MAttributePattern & | rhs | ) | const

Determine equality between two attribute patterns.

Parameters:

  [in] | rhs | Pattern to be compared

Returns:
  true if they both point to the same underlying Maya pattern

MAttributePattern * findPattern | ( | const MString & | name | ) | `[static]`

Search for all occurrences

Look up an existing pattern by name.

Parameters:

  [in] | name | The name of the pattern to be found

Returns:
  Pattern with the given name, NULL if not found

unsigned int attrPatternCount | ( |  | ) | `[static]`

Search for all occurrences

Get the number of patterns currently known.

Returns:
  Number of patterns that have been created.

MAttributePattern * attrPattern | ( | unsigned int | n | ) | `[static]`

Search for all occurrences

Look up an existing pattern by index value.

Parameters:

  [in] | n | The index in the global list of the pattern to be found

Returns:
  Pattern with the given index, NULL if out of range

MString name | ( | MStatus * | ReturnStatus = `NULL` | ) | const

Search for all occurrences

Get the name of this pattern.

Parameters:

  [out] | ReturnStatus | Did the operation return valid data?

Returns:
  Name of this pattern.

Status Codes:
  - MS::kSuccess The name was successfully returned.
  - MS::kFailure Object error.

unsigned int rootAttrCount | ( | MStatus * | ReturnStatus = `NULL` | ) | const

Search for all occurrences

Get the number of top level attributes present in this pattern.

Parameters:

  [out] | ReturnStatus | Did the operation return valid data?

Returns:
  Number of root attributes present in this pattern

Status Codes:
  - MS::kSuccess The count was successfully returned.
  - MS::kFailure Object error.

MObject rootAttr | ( | unsigned int | idx,
|  | MStatus * | ReturnStatus = `NULL`
| ) |  | const

Search for all occurrences

Get a single root-level attribute from this pattern.

Parameters:

  [in] | idx | Index of the root-level attribute in the pattern's list.
  [out] | ReturnStatus | Did the operation return valid data?

Returns:
  The idx'th root attribute present in the pattern.

Status Codes:
  - MS::kSuccess The attribute was successfully returned.
  - MS::kInvalidParameter There is no attribute at the given index.
  - MS::kFailure Object error.

MStatus removeRootAttr | ( | unsigned int | idx | ) |

Search for all occurrences

Remove a single root attribute and its children from the pattern by index.

Parameters:

  [in] | idx | Index of the root attribute to be removed

Returns:
  Status code of the operation's success

Status Codes:
  - MS::kSuccess The attribute was successfully removed from the pattern.
  - MS::kInvalidParameter There is no attribute at the given index.
  - MS::kFailure Object error.

MStatus removeRootAttr | ( | const MObject & | attr | ) |

Search for all occurrences

Remove a single root attribute and its children from the pattern by attribute.

Parameters:

  [in] | attr | The attribute to be removed

Returns:
  Status code of the operation's success

Status Codes:
  - MS::kSuccess The attribute was successfully removed from the pattern
  - MS::kFailure Removal was not possible.
  - MS::kInvalidParameter The given attribute is not in this pattern or is not a root

MStatus addRootAttr | ( | const MObject & | attr | ) |

Search for all occurrences

Add a new root attribute to the pattern.

Parameters:

  [in] | attr | Attribute to be added to this pattern.

Returns:
  Status code of the operation's success

Status Codes:
  - MS::kSuccess The attribute was successfully added to the pattern
  - MS::kFailure Addition was not possible.
  - MS::kInvalidParameter The given attribute is already in this pattern or is not a root

const char * className | ( |  | ) | `[static]`

Search for all occurrences

Returns the name of this class.

Returns:
  Name of this class.

MAttributePattern MAttributePattern MAttributePattern MAttributePattern MAttributePattern MAttributePattern MAttributePattern MAttributePattern MAttributePattern MAttributePattern
MAttributePattern MAttributePattern MAttributePattern MAttributePattern MAttributePattern MAttributePattern MAttributePattern MAttributePattern MAttributePattern MAttributePattern