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

- Class List
- Class Hierarchy
- Class Members

Public Types | Public Member Functions | Protected Member Functions

# MPxConstraintCommand Class Reference
OpenMayaAnim - API module for animation | Proxy classes

This reference page is linked to from the following overview topics: MPxNode and its derived classes, Removal of MStatus return codes from .NET API, Example C++ plug-in descriptions.

Search for all occurrences

## Detailed Description

Proxy constraint command.

MPxConstraintCommand is the base class for user defined constraint commands. This command gives all of the flags and options of the base constraint command in addition allows user defined flags or behaviours. When registering this command, use the MFnPlugin::registerConstraintCommand() method. A MPxConstraint is also required to be used with MPxConstraintCommand. The constraintTypeId() virtual must be implemented to return the correct constraint node.

Examples:

  geometrySurfaceConstraint.h.

`#include <MPxConstraintCommand.h>`

Inheritance diagram for MPxConstraintCommand:
[legend]

List of all members.

## Public Types
enum | TargetType { kTransform, kGeometryShape, kLast }
| Defines the type of target object. More...
## Public Member Functions
| MPxConstraintCommand ()
| Constructor.
virtual | ~MPxConstraintCommand ()
| Destructor.
virtual MStatus | doIt (const MArgList &argList)
| This method should execute a command by setting up internal class data and then return control to Maya for executing the base constraint command functionality.
virtual MStatus | undoIt ()
| This method should undo the work done be the redoIt method based on the internal class data only.
virtual MStatus | redoIt ()
| This method should do the actual work of the command based on the internal class data only.
virtual MStatus | appendSyntax ()
| This method should be overridden to append syntax to the constraint command.
## Protected Member Functions
virtual MStatus | parseArgs (const MArgList &argList)
| This method is used for parsing any custom flags/params that have been added to the command.
MSyntax | syntax (MStatus *ReturnStatus=NULL) const
| USE _syntax() IN SCRIPT.
virtual MStatus | doEdit ()
| This method is used for editing any custom setting on the command.
virtual MStatus | doCreate ()
| This method is used for creating resources required by the command.
virtual MStatus | doQuery ()
| This method is used for querying information defined in the command.
virtual void | createdConstraint (MPxConstraint *constraint)
| This method is called when an MPxConstraintCommand creates a new MPxConstraint node.
virtual bool | supportsOffset () const
| This method is used to control if the constraint supports offset.
virtual bool | hasVectorFlags () const
| This method is used to control if the constraint supports the base class vector flags.
virtual MTypeId | constraintTypeId () const
| This method is used to return the MTypeId of the MPxConstraint node that is used with this command.
virtual MPxConstraintCommand::TargetType | targetType () const
| Maya supports constraints targets which are either transforms or nodes derived from "geometryShape".
virtual const MObject & | aimVectorAttribute () const
| This method returns an attribute which defines the aim vector of a constraint.
virtual const MObject & | upVectorAttribute () const
| This method returns an upVector attribute that is used in conjunction with the aimVector.
virtual const MObject & | worldUpMatrixAttribute () const
| This method returns an worldUpMatrix attribute that is used in conjunction with the aimVector.
virtual const MObject & | worldUpTypeAttribute () const
| This method returns an worldUpType attribute that is used in conjunction with the aimVector.
virtual const MObject & | worldUpVectorAttribute () const
| This method returns an worldUpVector attribute that is used in conjunction with the aimVector.
virtual const MObject & | offsetAttribute () const
| This method returns the offset attribute and must be implemented if supportsOffset() returns true.
virtual const MObject & | constraintInstancedAttribute () const
| This method returns the attribute on the constraint node that connects to an instanced constraint attribute of the constrained object.
virtual const MObject & | constraintOutputAttribute () const
| This method returns the attribute this constraint will connect to the constrained attribute of the constrained object.
virtual const MObject & | constraintRestAttribute () const
| This method returns the rest state attribute for the constraint.
virtual const MObject & | constraintEnableRestAttribute () const
| This method returns the constraintReset attribute for the constraint.
virtual const MObject & | constraintTargetInstancedAttribute () const
| This method returns the constraintTargetInstanced attribute for the constraint.
virtual const MObject & | constraintTargetAttribute () const
| This method returns the constraintTarget attribute for the constraint.
virtual const MObject & | constraintTargetWeightAttribute () const
| This method returns the constraintTargetWeight attribute for the constraint.
virtual const MObject & | objectAttribute () const
| This method returns the attribute this constraint will drive on the constrained object.
virtual void | getObjectAttributesArray (MObjectArray &array)
| This method returns the list of attributes this particular constraint considers when inserting a pair blend.
virtual void | handleNewTargets (MObject &dagObject)
| This method is obsolete. This method is not available in Python.
virtual MStatus | handleNewTargets (MDagPath &dagObject)
| This method is used to perform any special processing when targets are added to the constraint.
virtual MStatus | connectTarget (void *opaqueTarget, int index)
| This method is obsolete. This method is not available in Python.
virtual MStatus | connectTarget (MDagPath &targetPath, int index)
| This method is called to make connections between the constraint and the target.
virtual MStatus | connectObjectAndConstraint (MDGModifier &modifier)
| This method is used for connecting the constraint and constrained object.
MStatus | connectGeometryAttribute (void *opaqueTarget, int index, MObject &constraintAttr)
| Utility method to make any required connections for the constraint.
MStatus | connectTargetAttribute (void *opaqueTarget, int index, MObject &constraintAttr)
| This method is obsolete. This method is not available in Python.
MStatus | connectTargetAttribute (MDagPath &targetPath, int index, MObject &tarAttr, MObject &constraintAttr, bool instanced=false)
| Utility method to make any required connections for the constraint.
MStatus | connectObjectAttribute (const MObject &objectAttr, const MObject &constraintAttr, bool toConstraint=true, bool instanced=false)
| This method can be used by connectObjectAndConstraint() to make any required connections between the constraint and the constrained object.
const MObject | transformObject ()
| This method returns the target object being constrained.

## Member Enumeration Documentation

enum TargetType

Search for all occurrences

Defines the type of target object.

Enumerator:

  kTransform | Transform target. Search for all occurrences
  kGeometryShape | Geometry shape(or children of) targets. Search for all occurrences
  kLast | Last value, used for counting. Search for all occurrences

## Constructor & Destructor Documentation

~MPxConstraintCommand | ( |  | ) | `[virtual]`

Destructor.

Local class data should be freed here.

## Member Function Documentation

MStatus doIt | ( | const MArgList & | args | ) | `[virtual]`

Search for all occurrences

This method should execute a command by setting up internal class data and then return control to Maya for executing the base constraint command functionality.

This is a virtual, and can be overridden in derived classes.

Default behaviour returns MS::kUnknownParameter so that Maya handles the operation.

Parameters:

  [in] | args | the command's argument list.

Returns:
  Status code

Status Codes:
  - MS::kSuccess The command was successful
  - MS::kFailure An error occurred during the command

Reimplemented from MPxCommand.

Examples:
  geometrySurfaceConstraint.h.

MStatus undoIt | ( |  | ) | `[virtual]`

Search for all occurrences

This method should undo the work done be the redoIt method based on the internal class data only.

Default behaviour returns MS::kUnknownParameter so that Maya handles the operation.

Returns:
  Status code

Status Codes:
  - MS::kSuccess The undo was successful
  - MS::kFailure This method is not undoable

Reimplemented from MPxCommand.

MStatus redoIt | ( |  | ) | `[virtual]`

Search for all occurrences

This method should do the actual work of the command based on the internal class data only.

Internal class data should be set in the doIt method.

Default behaviour returns MS::kUnknownParameter so that Maya handles the operation.

Returns:
  Status code

Status Codes:
  - MS::kSuccess The redo was successful
  - MS::kFailure An error occurred during the redo

Reimplemented from MPxCommand.

MStatus appendSyntax | ( |  | ) | `[virtual]`

Search for all occurrences

This method should be overridden to append syntax to the constraint command.

The syntax object can be obtained by calling the syntax method. The following flags cannot be used as user-defined flags as they are reserved for edit and query: "-e", "-edit", "-q", "-query".

Standard constraint flags that are provided are: name "-n" "-name", weight "-w" "-weight", target list "-tl" "-targetList", remove "-rm" "-remove", target alias "-wal" "-weightAliasList".

Returns:
  - MS::kSuccess operation successful
  - MS::kFailure operation failed

Examples:
  geometrySurfaceConstraint.h.

MStatus parseArgs | ( | const MArgList & | argList | ) | `[protected, virtual]`

Search for all occurrences

This method is used for parsing any custom flags/params that have been added to the command.

Return MS::kUnknownParameter to allow the processing of base flags/params.

Default behaviour returns MS::kUnknownParameter so that Maya handles the operation.

Parameters:

  [in] | argList | the command's argument list.

Returns:
  Status code

Status Codes:
  - MS::kSuccess The parseArgs was successful
  - MS::kFailure An error occurred during the parseArgs

Examples:
  geometrySurfaceConstraint.h.

MSyntax syntax | ( | MStatus * | ReturnStatus = `NULL` | ) | const`[protected]`

Search for all occurrences

USE _syntax() IN SCRIPT.

This method returns the syntax object of this constraint command.

The syntax object can be appended to in an overridden version of the appendSyntax method.

Parameters:

  [out] | ReturnStatus | return status

Returns:
  - the syntax object

Status Codes:
  - MS::kSuccess operation successful
  - MS::kFailure operation failed

MStatus doEdit | ( |  | ) | `[protected, virtual]`

Search for all occurrences

This method is used for editing any custom setting on the command.

Return MS::kUnknownParameter to allow processing of the base class functionality.

Default behaviour returns MS::kUnknownParameter so that Maya handles the operation.

Returns:
  Status code

Status Codes:
  - MS::kSuccess The edit was successful
  - MS::kFailure An error occurred during the edit

MStatus doCreate | ( |  | ) | `[protected, virtual]`

Search for all occurrences

This method is used for creating resources required by the command.

Return MS:kUnknownParameter to allow processing of base class functionality.

Default behaviour returns MS::kUnknownParameter so that Maya handles the operation.

Returns:
  Status code

Status Codes:
  - MS::kSuccess The create was successful
  - MS::kFailure An error occurred during the create

MStatus doQuery | ( |  | ) | `[protected, virtual]`

Search for all occurrences

This method is used for querying information defined in the command.

Return MS:kUnknownParameter to allow processing of base class functionality.

Default behaviour returns MS::kUnknownParameter so that Maya handles the operation.

Returns:
  Status code

Status Codes:
  - MS::kSuccess The query was successful
  - MS::kFailure An error occurred during the query

void createdConstraint | ( | MPxConstraint * | constraint | ) | `[protected, virtual]`

Search for all occurrences

This method is called when an MPxConstraintCommand creates a new MPxConstraint node.

It can be used for transferring state from the command to the node object.

Parameters:

  [in] | constraint | the constraint node created by the command.

Examples:
  geometrySurfaceConstraint.h.

bool supportsOffset | ( |  | ) | const`[protected, virtual]`

Search for all occurrences

This method is used to control if the constraint supports offset.

Return true if the constraint should support offset. False is returned otherwise and is the default behaviour of this method.

If this method returns true, then the offsetAttribute() method should return a 3 double attribute.

bool hasVectorFlags | ( |  | ) | const`[protected, virtual]`

Search for all occurrences

This method is used to control if the constraint supports the base class vector flags.

Return true if the constraint should support the vector flags. False is returned otherwise and is the default behaviour of this method.

If this method returns true, then the following methods need to return valid attributes: aimVectorAttribute(), upVectorAttribute() worldUpMatrixAttribute(), worldUpTypeAttribute(), worldUpVectorAttribute().

MTypeId constraintTypeId | ( |  | ) | const`[protected, virtual]`

Search for all occurrences

This method is used to return the MTypeId of the MPxConstraint node that is used with this command.

This virtual must be implemented in a proxy constraint command.

This method must be implemented.

Examples:
  geometrySurfaceConstraint.h.

MPxConstraintCommand::TargetType targetType | ( |  | ) | const`[protected, virtual]`

Search for all occurrences

Maya supports constraints targets which are either transforms or nodes derived from "geometryShape".

Return the appropriate target type in this method.

By default, this method returns MPxConstraintCommand::kTransform.

Examples:
  geometrySurfaceConstraint.h.

const MObject & aimVectorAttribute | ( |  | ) | const`[protected, virtual]`

Search for all occurrences

This method returns an attribute which defines the aim vector of a constraint.

The aimVector attribute defines a vector in the space of the constrained object that should be aligned with the weighted average vector computed by the constraint. The upVectorAttribute(), worldUpVectorAttribute(), worldUpMatrixAttribute, and worldUpTypeAttribute() define how the constrained object is rotated about the aimVector.

The aimVector returned should be a 3 double attribute.

The default behaviour of the method is to return a MObject::kNullObj.

const MObject & upVectorAttribute | ( |  | ) | const`[protected, virtual]`

Search for all occurrences

This method returns an upVector attribute that is used in conjunction with the aimVector.

The upVector returned should be a 3 double attribute.

The default behaviour of the method is to return a MObject::kNullObj.

const MObject & worldUpMatrixAttribute | ( |  | ) | const`[protected, virtual]`

Search for all occurrences

This method returns an worldUpMatrix attribute that is used in conjunction with the aimVector.

The worldUpMatrix returned should be a matrix attribute.

The default behaviour of the method is to return a MObject::kNullObj.

const MObject & worldUpTypeAttribute | ( |  | ) | const`[protected, virtual]`

Search for all occurrences

This method returns an worldUpType attribute that is used in conjunction with the aimVector.

The worldUpType returned should be a enum attribute.

The default behaviour of the method is to return a MObject::kNullObj.

const MObject & worldUpVectorAttribute | ( |  | ) | const`[protected, virtual]`

Search for all occurrences

This method returns an worldUpVector attribute that is used in conjunction with the aimVector.

The worldUpVector returned should be a 3 double attribute.

The default behaviour of the method is to return a MObject::kNullObj.

const MObject & offsetAttribute | ( |  | ) | const`[protected, virtual]`

Search for all occurrences

This method returns the offset attribute and must be implemented if supportsOffset() returns true.

The offset returned should be a 3 double attribute.

The default behaviour of the method is to return a MObject::kNullObj.

const MObject & constraintInstancedAttribute | ( |  | ) | const`[protected, virtual]`

Search for all occurrences

This method returns the attribute on the constraint node that connects to an instanced constraint attribute of the constrained object.

The type of the attribute will depend on the constraint implementation.

The default behaviour of the method is to return a MObject::kNullObj.

Examples:
  geometrySurfaceConstraint.h.

const MObject & constraintOutputAttribute | ( |  | ) | const`[protected, virtual]`

Search for all occurrences

This method returns the attribute this constraint will connect to the constrained attribute of the constrained object.

The type of the attribute will depend on the constraint implementation.

The default behaviour of the method is to return a MObject::kNullObj.

Examples:
  geometrySurfaceConstraint.h.

const MObject & constraintRestAttribute | ( |  | ) | const`[protected, virtual]`

Search for all occurrences

This method returns the rest state attribute for the constraint.

Constraints supporting rest state should implement this method.

The constraintReset attribute is a 3 double.

The default behaviour of the method is to return a MObject::kNullObj.

const MObject & constraintEnableRestAttribute | ( |  | ) | const`[protected, virtual]`

Search for all occurrences

This method returns the constraintReset attribute for the constraint.

The constraintReset attribute is a boolean.

The default behaviour of the method is to return a MObject::kNullObj.

const MObject & constraintTargetInstancedAttribute | ( |  | ) | const`[protected, virtual]`

Search for all occurrences

This method returns the constraintTargetInstanced attribute for the constraint.

The type of the attribute will depend on the constraint implementation. Suggested attribute types include a parent matrix or target geometry.

The default behaviour of the method is to return a MObject::kNullObj.

Examples:
  geometrySurfaceConstraint.h.

const MObject & constraintTargetAttribute | ( |  | ) | const`[protected, virtual]`

Search for all occurrences

This method returns the constraintTarget attribute for the constraint.

The type of the attribute will depend on the constraint implementation. But it must be an compound array attribute.

The default behaviour of the method is to return a MObject::kNullObj.

Examples:
  geometrySurfaceConstraint.h.

const MObject & constraintTargetWeightAttribute | ( |  | ) | const`[protected, virtual]`

Search for all occurrences

This method returns the constraintTargetWeight attribute for the constraint.

The type of the constraintTargetWeight attribute is a double.

The default behaviour of the method is to return a MObject::kNullObj.

Examples:
  geometrySurfaceConstraint.h.

const MObject & objectAttribute | ( |  | ) | const`[protected, virtual]`

Search for all occurrences

This method returns the attribute this constraint will drive on the constrained object.

The default behaviour of the method is to return a MObject::kNullObj.

Examples:
  geometrySurfaceConstraint.h.

void getObjectAttributesArray | ( | MObjectArray & | array | ) | `[protected, virtual]`

Search for all occurrences

This method returns the list of attributes this particular constraint considers when inserting a pair blend.

Parameters:

  [in] | array | Array of attributes.

void handleNewTargets | ( | MObject & | dagObject | ) | `[protected, virtual]`

Search for all occurrences

This method is obsolete. This method is not available in Python.

Deprecated:
  Use MPxConstraintCommand::handleNewTargets( MDagpath& dagObject ) instead.

Parameters:

  [in] | dagObject |

MStatus handleNewTargets | ( | MDagPath & | dagObject | ) | `[protected, virtual]`

Search for all occurrences

This method is used to perform any special processing when targets are added to the constraint.

For example, the constraint may need to keep track of the list of targets to properly calculate an offset.

Parameters:

  [in] | dagObject | path to the new constraint target

MStatus connectTarget | ( | void * | opaqueTarget,
|  | int | index
| ) |  | `[protected, virtual]`

Search for all occurrences

This method is obsolete. This method is not available in Python.

Deprecated:
  Use MPxConstraintCommand::connectTarget(MDagPath &targetPath, int index) instead.

Parameters:

  [in] | opaqueTarget |
  [in] | index |

Examples:
  geometrySurfaceConstraint.h.

MStatus connectTarget | ( | MDagPath & | targetPath,
|  | int | index
| ) |  | `[protected, virtual]`

Search for all occurrences

This method is called to make connections between the constraint and the target.

Since the default behaviour is to do nothing it is generally necessary to override this method if your constraint is to work properly. The connectTargetAttribute() convenience method can be useful in this regard.

Default behaviour makes no connections.

Parameters:

  [in] | targetPath | DAG path of the target
  [in] | index | index for this target in the node's constraint target attribute

Returns:
  Status code

Status Codes:
  - MS::kSuccess The method was successful
  - MS::kFailure An error occurred

MStatus connectObjectAndConstraint | ( | MDGModifier & | modifier | ) | `[protected, virtual]`

Search for all occurrences

This method is used for connecting the constraint and constrained object.

The utility method MPxConstraintCommand::connectObjectAttribute() is used to connect the attributes.

Default behaviour returns MS::kUnknownParameter so that Maya handles the operation.

Parameters:

  [in] | modifier | used for setting plug values such as translation

Returns:
  Status code

Status Codes:
  - MS::kSuccess The method was successful
  - MS::kFailure An error occurred

Examples:
  geometrySurfaceConstraint.h.

MStatus connectGeometryAttribute | ( | void * | opaqueTarget,
|  | int | index,
|  | MObject & | constraintAttribute
| ) |  | `[protected]`

Search for all occurrences

Utility method to make any required connections for the constraint.

Note that it is called by the default implementation of connectTarget().

Parameters:

  [in] | opaqueTarget | as passed to connectTarget()
  [in] | index | as passed to connectTarget()
  [in] | constraintAttribute | as defined by the constraint

Returns:
  Status code

Status Codes:
  - MS::kSuccess The method was successful
  - MS::kFailure An error occurred during the method

MStatus connectTargetAttribute | ( | void * | opaqueTarget,
|  | int | index,
|  | MObject & | constraintAttribute
| ) |  | `[protected]`

Search for all occurrences

This method is obsolete. This method is not available in Python.

Deprecated:
  Use MPxConstraintCommand::connectTargetAttribute(MDagPath &targetPath, int index) instead.

Parameters:

  [in] | opaqueTarget |
  [in] | index |
  [in] | constraintAttribute |

MStatus connectTargetAttribute | ( | MDagPath & | targetPath,
|  | int | index,
|  | MObject & | targetAttribute,
|  | MObject & | constraintAttr,
|  | bool | instanced = `false`
| ) |  | `[protected]`

Search for all occurrences

Utility method to make any required connections for the constraint.

Parameters:

  [in] | targetPath | as passed to connectTarget()
  [in] | index | as passed to connectTarget()
  [in] | targetAttribute | as defined by the target
  [in] | constraintAttr | as defined by the constraint
  [in] | instanced | true if targetAttribute is an instanced attribute

Returns:
  Status code

Status Codes:
  - MS::kSuccess The method was successful
  - MS::kFailure An error occurred during the method

MStatus connectObjectAttribute | ( | const MObject & | objectAttr,
|  | const MObject & | constraintAttr,
|  | bool | toConstraint = `true`,
|  | bool | instanced = `false`
| ) |  | `[protected]`

Search for all occurrences

This method can be used by connectObjectAndConstraint() to make any required connections between the constraint and the constrained object.

Parameters:

  [in] | objectAttr | as passed to connectTarget()
  [in] | constraintAttr | as defined by the constraint
  [in] | toConstraint | true if connection is from object to constraint, false if connection is from constraint to object
  [in] | instanced | true if objectAttr must be indexed by instance number

Returns:
  Status code

Status Codes:
  - MS::kSuccess The method was successful
  - MS::kFailure An error occurred during the method

const MObject transformObject | ( |  | ) | `[protected]`

Search for all occurrences

This method returns the target object being constrained.

The object returned will be a "transform" node. This node can be queried using MFnTransform to extract information such as translate, scale etc which will allow the placement of the constrained object in a reasonable default location. For example, a geometric constraint may wish to place the constrained object on top of the target.

MPxConstraintCommand MPxConstraintCommand MPxConstraintCommand MPxConstraintCommand MPxConstraintCommand MPxConstraintCommand MPxConstraintCommand MPxConstraintCommand MPxConstraintCommand MPxConstraintCommand
MPxConstraintCommand MPxConstraintCommand MPxConstraintCommand MPxConstraintCommand MPxConstraintCommand MPxConstraintCommand MPxConstraintCommand MPxConstraintCommand MPxConstraintCommand MPxConstraintCommand