## SIApplyConstraint

### Description

Constrains an object to one or more constraining objects. Constraints are placed under the kinematics property of the constrained object. SIApplyConstraint differs from ApplyCns and SIApplyCns in that it has parameters for directly controlling the constraint's offsets. When both compensating and passing offsets, the offset values take precedence over compensation.

### Scripting Syntax

    oReturn = SIApplyConstraint( PresetObj, [ConstrainedObj], [ConstrainingObj], [Compensation], [Offset1X], [Offset1Y], [Offset1Z], [Offset2X], [Offset2Y], [Offset2Z] );

### Return Value

Returns an XSICollection containing the new Constraint object(s).

### Parameters

Parameter | Type | Description
--- | --- | ---
PresetObj | String or a preset object (see SIGetPreset) | Constraint preset. Warning: The preset name is case-sensitive on Linux.
ConstrainedObj | String | List of objects to be constrained. Default Value: Selected objects
ConstrainingObj | String | List of constraining objects. Default Value: Selected objects
Compensation | Boolean | True to turn on compensation Default Value: False
Offset1X | Number | X offset value
Possible Values: | Description:
RotationOffset(Orientationconstraint) |
TargetOffset(Directionconstraint) |
ScalingOffset(Scalingconstraint) |
ConstrainedObjectAttachPoint(Distance,Position,Surface,Trajectoryconstraints) |
Offset1Y | Number | Y offset value
Possible Values: | Description:
RotationOffset(Orientationconstraint) |
TargetOffset(Directionconstraint) |
ScalingOffset(Scalingconstraint) |
ConstrainedObjectAttachPoint(Distance,Position,Surface,Trajectoryconstraints) |
Offset1Z | Number | Z offset value
Possible Values: | Description:
RotationOffset(Orientationconstraint) |
TargetOffset(Directionconstraint) |
ScalingOffset(Scalingconstraint) |
ConstrainedObjectAttachPoint(Distance,Position,Trajectory,Surface,Trajectoryconstraints) |
Offset2X | Number | X offset value
Possible Values: | Description:
ConstrainingObjectAttachPoint(Distance,Positionconstraints) |
Offset2Y | Number | Y offset value
Possible Values: | Description:
ConstrainingObjectAttachPoint(Distance,Positionconstraints) |
Offset2Z | Number | Z offset value
Possible Values: | Description:
ConstrainingObjectAttachPoint(Distance,Positionconstraints) |

### Examples

#### VBScript Example

    '

    ' Orientation constrain two cones to a cube, compensating one of them.

    '

    dim oCube, oConeCompensated, oConeUncompensated

    '

    ' get a cube and rotate it so we can see how orientation is being constrained.

    '

    set oCube = GetPrim("Cube")

    oCube.length = 2

    Scale oCube, 0.5, 3, 0.5, siRelative, siLocal, siObj, siXYZ

    Rotate oCube, 45, 0, 45, siRelative, siAdd, siObj, siXYZ

    '

    ' create the two cones and put on either side of the cube

    '

    set oConeCompensated = GetPrim("Cone")

    Translate oConeCompensated, -4, 0, 0, siAbsolute, siParent, siObj, siXYZ

    set oConeUncompensated = GetPrim("Cone")

    Translate oConeUncompensated, 4, 0, 0, siAbsolute, siParent, siObj, siXYZ

    '

    ' Apply the constraint

    ' Offset one cone's orientation by 30 degrees about each axis

    '

    SIApplyConstraint "Orientation", oConeCompensated, oCube, false, 30,30,30

    SIApplyConstraint "Orientation", oConeUncompensated, oCube, false

    '

    ' display the constraint relationship in the camera view

    '

    SetValue "Camera.camvis.*constraint*", True

    '

    ' log the constraint offsets to show

    ' that one has been compensated

    '

    dim comp_x,comp_y,comp_z,uncomp_x,uncomp_y,uncomp_z

    comp_x = GetValue( oConeCompensated&".kine.oricns.offx")

    comp_y = GetValue( oConeCompensated&".kine.oricns.offy")

    comp_z = GetValue( oConeCompensated&".kine.oricns.offz")

    uncomp_x = GetValue( oConeUncompensated&".kine.oricns.offx")

    uncomp_y = GetValue( oConeUncompensated&".kine.oricns.offy")

    uncomp_z = GetValue( oConeUncompensated&".kine.oricns.offz")

    logmessage "Compensated cone offsets:   x= " & comp_x   & " y= " & comp_y   & " z= " & comp_z

    logmessage "Uncompensated cone offsets: x= " & uncomp_x & " y= " & uncomp_y & " z= " & uncomp_z

    'Results of running this script:

    'INFO : "Compensated cone offsets:   x= 30 y= 30 z= 30"

    'INFO : "Uncompensated cone offsets: x= 0 y= 0 z= 0"

### See Also

SIApplyCns RemoveAllCns RemoveCns