Description
Applies a constraint on one or more objects based on a constraining object. For example, you can constrain the position of one object with the position of another. After creating a constraint, it is not possible to change the value(s) affected in the constrained object; you can only change value(s) in the constraining object.
For example, when you apply a Position constraint between two objects, you can change the XYZ position of the constraining object only. Conversely, if you change a value on the constraining object, the corresponding value on the constrained object is automatically changed.
Scripting Syntax
ApplyCns( PresetObj, [ConstrainedObj], [ConstrainingObj], [Compensation] )
Parameters
|
Parameter |
Type |
Description |
|
PresetObj |
String or a preset object (see SIGetPreset) |
One of the . Warning: The preset name is case-sensitive on Linux. |
|
ConstrainedObj [in/out] |
List of objects to be constrained. If you pass in a variable, the command returns a XSICollection of the constrained objects. Default Value: Selected objects |
|
|
ConstrainingObj [in/out] |
List of constraining objects. If you pass in a variable, the command returns a XSICollection of the constraining objects. Default Value: User is prompted to pick |
|
|
Compensation [in/out] |
True to turn on compensation Default Value: False |
Return Value
Returns an XSICollection containing the Constraint objects.
Examples
VBScript Example
'
' This example creates a little planetary scene and applies 2 constraints
' from the planet to the ring: a Position and a Scaling constraint. Then
' it removes only the Scaling constraint by using the RemoveCnsType command
' and verifies this by printing out a list of constraints on each object
' before and after removing the constraints.
'
' Create a planet that will serve as the constraining object
set oPlanet = CreatePrim( "Sphere", "NurbsSurface", "Planet" )
' Create a moon to be constrained by the planet and scale it
set oMoon = CreatePrim( "Sphere", "NurbsSurface", "Moon" )
Translate oMoon, -6, 4, -5, siRelative, siView, siObj, siXYZ
Scale oMoon, 0.15, 0.15, 0.15, siAbsolute, siParent, siObj, siXYZ
' Create a ring to be constrained by the planet and scale it
set oRing = CreatePrim( "Disc", "NurbsSurface", "Ring" )
Scale oRing, 2.3, 1, 2.3, siAbsolute, siParent, siObj, siXYZ
' Check to see if any constraints are currently set
getCnsInfo oPlanet
getCnsInfo oMoon
getCnsInfo oRing
' Apply a Position constraint on the ring and the moon from the planet.
' (The small sphere and the disc depend on the position of the larger sphere.)
' Notice that you have to pass the name of the object instead of its object
' variable with this command because the command changes that variable to a
' different type
ApplyCns "Position", oMoon.Name & "," & oRing.Name, "Planet", true
' Check to see which constraints are currently set
getCnsInfo oPlanet
getCnsInfo oMoon
getCnsInfo oRing
' Display the constraint relationship in all the default views and
' the default camera view. This is the equivalent of turning on
' "Relation" and "Relation Info" in the view visibility options.
SetValue "Views.*.*.camvis.*constraint*", True
SetValue "Camera.camvis.*constraint*", True
' This function just saves us time and typing
function getCnsInfo( in_constrained_obj )
set oFoundCns = in_constrained_obj.Kinematics.Constraints
if oFoundCns.Count > 0 then
LogMessage "Found the following constraints on the " & in_constrained_obj & ":"
for each c in oFoundCns
LogMessage vbTab & c.Name
next
else
LogMessage "No constraints found on " & in_constrained_obj
end if
end function
' Output of the above script:
'
' ...before applying the constraint:
'INFO : "No constraints found on Planet"
'INFO : "No constraints found on Moon"
'INFO : "No constraints found on Ring"
'
' ...after applying the constraint:
'INFO : "No constraints found on Planet"
'INFO : "Found the following constraints on the Moon:"
'INFO : " Position Cns"
'INFO : "Found the following constraints on the Ring:"
'INFO : " Position Cns"
See Also
SOFTIMAGE|XSI v6.01