pymel.core.animation.parentConstraint

parentConstraint(*args, **kwargs)

Constrain an object’s position and rotation so that it behaves as if it were a child of the target object(s). In the case of multiple targets, the overall position and rotation of the constrained object is the weighted average of each target’s contribution to the position and rotation of the object. A parentConstraint takes as input one or more “target” DAG transform nodes at which to position and rotate the single “constraint object” DAG transform node. The parentConstraint positions and rotates the constrained object at the weighted average of the world space position, rotation and scale target objects.

Maya Bug Fix:
  • when queried, angle offsets would be returned in radians, not current angle unit
Modifications:
  • added new syntax for querying the weight of a target object, by passing the constraint first:

    aimConstraint( 'pCube1_aimConstraint1', q=1, weight ='pSphere1' )
    aimConstraint( 'pCube1_aimConstraint1', q=1, weight =['pSphere1', 'pCylinder1'] )
    aimConstraint( 'pCube1_aimConstraint1', q=1, weight =[] )
    
Flags:
Long name (short name) Argument Types Properties
createCache (cc) float, float ../../../_images/edit.gif
 

This flag is used to generate an animation curve that serves as a cache for the constraint. The two arguments define the start and end frames.The cache is useful if the constraint has multiple targets and the constraint’s interpolation type is set to “no flip”. The “no flip” mode prevents flipping during playback, but the result is dependent on the previous frame. Therefore in order to consistently get the same result on a specific frame, a cache must be generated. This flag creates the cache and sets the constraint’s interpolation type to “cache”. If a cache exists already, it will be deleted and replaced with a new cache.

deleteCache (dc) bool ../../../_images/edit.gif
 
Delete an existing interpolation cache.Flag can appear in Create mode of commandFlag can have multiple arguments, passed either as a tuple or a list.
layer (l) unicode ../../../_images/create.gif ../../../_images/edit.gif
 
Specify the name of the animation layer where the constraint should be added.
maintainOffset (mo) bool ../../../_images/create.gif
 
If this flag is specified the position and rotation of the constrained object will be maintained.
name (n) unicode ../../../_images/create.gif ../../../_images/query.gif ../../../_images/edit.gif
 
Sets the name of the constraint node to the specified name. Default name is constrainedObjectName_constraintType
remove (rm) bool ../../../_images/edit.gif
 
removes the listed target(s) from the constraint.
skipRotate (sr) unicode ../../../_images/create.gif
 
Causes the axis specified not to be considered when constraining rotation. Valid arguments are “x”, “y”, “z” and “none”.
skipTranslate (st) unicode ../../../_images/create.gif
 
Causes the axis specified not to be considered when constraining translation. Valid arguments are “x”, “y”, “z” and “none”.
targetList (tl) bool ../../../_images/query.gif
 
Return the list of target objects.
weight (w) float ../../../_images/create.gif ../../../_images/query.gif ../../../_images/edit.gif
 
Sets the weight value for the specified target(s). If not given at creation time, the default value of 1.0 is used.
weightAliasList (wal) bool ../../../_images/query.gif
 

Returns the names of the attributes that control the weight of the target objects. Aliases are returned in the same order as the targets are returned by the targetList flag

Derived from mel command maya.cmds.parentConstraint

Example:

import pymel.core as pm

import maya.cmds as cmds

# Position cube1 at the location of cone1
# Rotate cube1 to the rotation of cone1
pm.parentConstraint( 'cone1', 'cube1' )


# Position cube1 at the average of the locations of cone1 and surf2
# Rotate cube1 to the average of the rotations of cone1 and surf2
pm.parentConstraint( 'cone1', 'surf2', 'cube2', w=.1 )

# Sets the weight for cone1's effect on cube2 to 10.
pm.parentConstraint( 'cone1', 'cube2', e=True, w=10.0 )

# Removes surf2 from cube2's parentConstraint
pm.parentConstraint( 'surf2', 'cube2', e=True, rm=True )

# Adds surf3 to cube2's parentConstraint with the default weight
pm.parentConstraint( 'surf3', 'cube2' )

# Constrain position only in the y-axis with rotation
# constraining in all axes
pm.parentConstraint( 'cone2', 'cube2', st=["x","z"] )

Previous topic

pymel.core.animation.pairBlend

Next topic

pymel.core.animation.pasteKey

Core

Core Modules

Other Modules

This Page