C++ API Reference
MAttributePattern Class Reference

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

#include <MAttributePattern.h>

Public Member Functions

 MAttributePattern ()
 Default MAttributePattern object has no internal Maya object.
 
 MAttributePattern (const MString &name)
 Construct an MAttributePattern object with the given name. More...
 
 MAttributePattern (const MAttributePattern &rhs)
 Construct an MAttributePattern object from another pattern. More...
 
MAttributePatternoperator= (const MAttributePattern &rhs)
 Copy an MAttributePattern object from another pattern. More...
 
bool operator== (const MAttributePattern &rhs) const
 Determine equality between two attribute patterns. More...
 
 ~MAttributePattern ()
 Destructor, doesn't do much.
 
MString name (MStatus *ReturnStatus=NULL) const
 Get the name of this pattern. More...
 
unsigned int rootAttrCount (MStatus *ReturnStatus=NULL) const
 Get the number of top level attributes present in this pattern. More...
 
MObject rootAttr (unsigned int idx, MStatus *ReturnStatus=NULL) const
 Get a single root-level attribute from this pattern. More...
 
MStatus removeRootAttr (unsigned int idx)
 Remove a single root attribute and its children from the pattern by index. More...
 
MStatus removeRootAttr (const MObject &attr)
 Remove a single root attribute and its children from the pattern by attribute. More...
 
MStatus addRootAttr (const MObject &attr)
 Add a new root attribute to the pattern. More...
 

Static Public Member Functions

static MAttributePatternfindPattern (const MString &name)
 Look up an existing pattern by name. More...
 
static unsigned int attrPatternCount ()
 Get the number of patterns currently known. More...
 
static MAttributePatternattrPattern (unsigned int n)
 Look up an existing pattern by index value. More...
 
static const char * className ()
 Returns the name of this class. More...
 

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;
MObject parentObj1 = parentAttr.create( "parent", "par", &status );
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) );

Constructor & Destructor Documentation

OPENMAYA_MAJOR_NAMESPACE_OPEN 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]nameName of the pattern

Construct an MAttributePattern object from another pattern.

The internal Maya object is shared between the two MAttributePatterns.

Parameters
[in]rhsPattern to be copied

Member Function Documentation

MAttributePattern & operator= ( const MAttributePattern rhs)

Copy an MAttributePattern object from another pattern.

Parameters
[in]rhsPattern to be copied
bool operator== ( const MAttributePattern rhs) const

Determine equality between two attribute patterns.

Parameters
[in]rhsPattern to be compared
Returns
true if they both point to the same underlying Maya pattern
MAttributePattern * findPattern ( const MString name)
static

Look up an existing pattern by name.

Parameters
[in]nameThe name of the pattern to be found
Returns
Pattern with the given name, NULL if not found
unsigned int attrPatternCount ( )
static

Get the number of patterns currently known.

Returns
Number of patterns that have been created.
MAttributePattern * attrPattern ( unsigned int  n)
static

Look up an existing pattern by index value.

Parameters
[in]nThe 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

Get the name of this pattern.

Parameters
[out]ReturnStatusDid 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

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

Parameters
[out]ReturnStatusDid 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

Get a single root-level attribute from this pattern.

Parameters
[in]idxIndex of the root-level attribute in the pattern's list.
[out]ReturnStatusDid 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)

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

Parameters
[in]idxIndex 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)

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

Parameters
[in]attrThe 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)

Add a new root attribute to the pattern.

Parameters
[in]attrAttribute 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

Returns the name of this class.

Returns
Name of this class.

The documentation for this class was generated from the following files: