Go to: Synopsis. Flags. Return value. Related. Python examples.
constrain([barrier=boolean], [damping=float], [directionalHinge=boolean], [hinge=boolean], [interpenetrate=boolean], [nail=boolean], [name=string], [orientation=[float, float, float]], [pinConstraint=boolean], [position=[float, float, float]], [restLength=float], [spring=boolean], [stiffness=float])
Note: Strings representing object names and arguments must be separated by commas. This is not depicted in the synopsis.
constrain is undoable, queryable, and editable.
This command constrains rigid bodies to the world or other rigid bodies.
barrier, damping, directionalHinge, hinge, interpenetrate, nail, name, orientation, pinConstraint, position, restLength, spring, stiffness
| Long name (short name) |
[argument types] |
Properties |
name(n)
|
string
|
 
|
|
Names the rigid constraint.
In query mode, this flag needs a value.
|
|
nail(na)
|
boolean
|

|
|
Creates a nail constraint. This command requires one rigid body.
In query mode, this flag needs a value.
|
|
pinConstraint(pin)
|
boolean
|

|
|
Creates a pin constraint. This command requires two rigid bodies.
In query mode, this flag needs a value.
|
|
hinge(hi)
|
boolean
|

|
|
Creates a hinge constraint. This command requires one or two rigid bodies.
In query mode, this flag needs a value.
|
|
directionalHinge(dhi)
|
boolean
|

|
|
Creates a directional hinge constraint. This command requires two rigid bodies.
The directional hinge always maintains the initial direction of its axis.
In query mode, this flag needs a value.
|
|
barrier(br)
|
boolean
|

|
|
Creates a barrier constraint. This command requires one rigid bodies.
In query mode, this flag needs a value.
|
|
spring(s)
|
boolean
|

|
|
Creates a spring constraint. This command requires one or two rigidies.
In query mode, this flag needs a value.
|
|
stiffness(st)
|
float
|
 
|
|
Sets the springs stiffness constant.
Default value: 5.0
In query mode, this flag needs a value.
|
|
damping(d)
|
float
|
 
|
|
Sets the damping constant.
Default value: 0.1
Range: -1000.0 to 1000.0
In query mode, this flag needs a value.
|
|
restLength(rl)
|
float
|
 
|
|
Sets the rest length.
Default value: 1.0
In query mode, this flag needs a value.
|
|
position(p)
|
[float, float, float]
|
 
|
|
Set initial position of the constraint in world space.
Default value: 0.0 0.0 0.0 for uni-constraints, midpoint of bodies for deul constraint.
In query mode, this flag needs a value.
|
|
orientation(o)
|
[float, float, float]
|
 
|
|
Set initial orientation of the constraint in world space. This
command is only valid with hinge and barrier constraints
Default value: 0.0 0.0 0.0
In query mode, this flag needs a value.
|
|
interpenetrate(i)
|
boolean
|
 
|
|
Allows (or disallows) the rigid bodies defined in the constrain to ipenetrate.
In query mode, this flag needs a value.
|
|
Flag can appear in Create mode of command
|
Flag can appear in Edit mode of command
|
Flag can appear in Query mode of command
|
Flag can have multiple arguments, passed either as a tuple or a list.
|
[nothing]
rigidBody, rigidSolver
import maya.cmds as cmds
# "Nail" a rigid body at position <<0.0, 2.5, 0.0>>
#
cmds.constrain( 'rigidBody1', nail=True, p=(0, 2.5, 0) )
# "Pin" two rigid bodies together at the position <<0.0, 2.5, 0.0>>.
#
cmds.constrain( 'rigidBody1', 'rigidBody2', pin=True, n='pin', p=(0, 2.5, 0) )
# "Hinge" a rigid body at the position <<0.0, 2.5, 0.0>>.
#
cmds.constrain( 'rigidBody1', hinge=True, p=(0, 2.5, 0) )
# Create a barrier for a rigid body which will not allow the rigid body
# to fall below (in y by default) the plane defined by the
# barrier point <<0.0, 2.5, 0.0>>.
#
cmds.constrain( 'rigidBody1', barrier=True, p=(0, 2.5, 0) )
# Add a "Spring" to a rigid body at the position <<0.0, 2.5, 0.0>>
# connected on the rigid body at point <<0, 0, 0>>
#
cmds.constrain( 'rigidBody1', spring=True, name='spring', p=(0, 2.5, 0), rl=1.0 )
Return to Autodesk Index