FCurveKey.Constraint
 
 
 

FCurveKey.Constraint

Description

Sets or returns a Boolean value indicating whether or not the specified fcurve key constraint is set. The siFCurveKeyConstraint values are of type Long (see siFCurveKeyConstraint for a list of possible values).

Warning: Getting and setting this property in Python is not supported. To set a specific constraint in Python, use the "Set" prefix with method syntax: 'fcrvkey.SetConstraint( c.siLockConstraint, true )'. This is demonstrated in the Python example below. To get a specific constraint, use the Python-compliant method FCurveKey.GetConstraint2 instead.

C# Syntax

// get accessor
Boolean FCurveKey.get_Constraint( siFCurveKeyConstraint in_eConstraint );
// set accessor
FCurveKey.set_Constraint( siFCurveKeyConstraint in_eConstraint, Boolean out_pVal );

Parameters

Parameter Type Description
Constraint siFCurveKeyConstraint The type of fcurve key constraint to set or return. You can add these values together to specify several constraints at once.

For example, use siParameterConstraint + siSameLengthTangentConstraint to lock all parameters and force left and right tangent lengths to be the same.

Examples

1. JScript Example

/* 
        This example illustrates how to create an fcurve with keys and then how to set a 
        constraint on one of the keys. 
*/ 
// ---------------------------------------------------------------------------------
// Functions and Setup
// ---------------------------------------------------------------------------------
function GetConsList(fckey,setchk)
{
        var dicConstraintTypes = new ActiveXObject( "Scripting.Dictionary" );
        dicConstraintTypes.Add( "LockParameter",                siParameterConstraint );
        dicConstraintTypes.Add( "LeftRightParameter",           siLeftRightValuesConstraint );
        dicConstraintTypes.Add( "G1Continuous",                 siG1ContinuousConstraint );
        dicConstraintTypes.Add( "LeftRightTangentDirection",    siLeftRightTangentDirectionConstraint );
        dicConstraintTypes.Add( "LeftRightTangentLength",       siLeftRightTangentLengthConstraint );
        dicConstraintTypes.Add( "LockAll",                      siLockConstraint );
        dicConstraintTypes.Add( "HorizontalTangent",            siHorizontalTangentConstraint );
        dicConstraintTypes.Add( "ExtremumHorizontalTangent",    siExtremumHorizontalTangentConstraint );
        dicConstraintTypes.Add( "AdjustedTangent",              siAdjustedTangentConstraint );
        dicConstraintTypes.Add( "ZeroLengthTangent",            siZeroLengthTangentConstraint );
        dicConstraintTypes.Add( "SameLengthTangent",            siSameLengthTangentConstraint );
        dicConstraintTypes.Add( "NeighborTangent",                      siNeighborTangentConstraint );
        dicConstraintTypes.Add( "MirrorTangent",                        siMirrorTangentConstraint );
        dicConstraintTypes.Add( "AutoPlateauTangent",           siAutoPlateauTangentConstraint );
        var strlist = "";
        var vbKeys = dicConstraintTypes.Keys();         // the Dictionary.Keys method returns a safearray
        var jsKeys = vbKeys.toArray();                  // that you can convert with the toArray() method
        for ( var k=0; k<jsKeys.length; k++ ) {
                if ( setchk == fckey.Constraint( dicConstraintTypes.Item(jsKeys[k]) ) ) {
                        strlist += jsKeys[k] + " ";
                }
        }
        return strlist;
}
// ---------------------------------------------------------------------------------
// Create new scene
// ---------------------------------------------------------------------------------
NewScene( null, false );
// Create a null
var n = Application.ActiveSceneRoot.AddNull()
// Add a custompvar to the null
var cpset = n.AddProperty( "Custom_parameter_list", false, "CustomPSet" );
// Add a double parameter to cpset
var x = cpset.AddParameter3( "X", siDouble, 0, -100, 100, 1 );
// Create a fcurve on posx
var fc = x.AddFCurve2( new Array(1,0.5), siStandardFCurve );
var fckey = fc.Keys(0);
// ---------------------------------------------------------------------------------
// Set the siLockConstraint ( time, value & tangents are locked )
// ---------------------------------------------------------------------------------
// Set the Constraint property 
fckey.Constraint( siLockConstraint ) = 1;
if ( fckey.Constraint(siLockConstraint) ) {
        Application.LogMessage( "fckey(" + fckey.Index + ") lock all constraints: true" );
} else {
        Application.LogMessage( "fckey(" + fckey.Index + ") lock all constraints: false" );
}
Application.LogMessage( "fckey(" + fckey.Index + ") constraints set: " + GetConsList(fckey,true) );
Application.LogMessage( "fckey(" + fckey.Index + ") constraints NOT set: " + GetConsList(fckey,false) );
// If you try and change the key value when the lock constraint is on it raises 
// an 'Access Denied' error.
try {
        fckey.Value = 5;
} catch(e) {
        if ( e.number ) {
                Application.LogMessage( "fckey(" + fckey.Index + ") set value failed: " + e.description );
        }
}
// ---------------------------------------------------------------------------------
// Expected results::
// ---------------------------------------------------------------------------------
//INFO : fckey(0) lock all constraints: true
//INFO : fckey(0) constraints set: LockParameter LeftRightParameter G1Continuous LeftRightTangentDirection LeftRightTangentLength LockAll AutoPlateauTangent
//INFO : fckey(0) constraints NOT set: HorizontalTangent ExtremumHorizontalTangent AdjustedTangent ZeroLengthTangent SameLengthTangent NeighborTangent MirrorTangent
//INFO : 2009 - fckey(0) set value failed: Access denied

2. VBScript Example

' 
' This example illustrates how to create an fcurve with keys and then how to set a constraint 
' on one of the keys. 
' 
' ---------------------------------------------------------------------------------
' Functions and Setup
' ---------------------------------------------------------------------------------
function GetConsList(fckey,setchk)
        set dicConstraintTypes = CreateObject( "Scripting.Dictionary" )
        dicConstraintTypes.Add "LockParameter",                 siParameterConstraint
        dicConstraintTypes.Add "LeftRightParameter",            siLeftRightValuesConstraint
        dicConstraintTypes.Add "G1Continuous",                  siG1ContinuousConstraint
        dicConstraintTypes.Add "LeftRightTangentDirection",     siLeftRightTangentDirectionConstraint
        dicConstraintTypes.Add "LeftRightTangentLength",        siLeftRightTangentLengthConstraint
        dicConstraintTypes.Add "LockAll",                       siLockConstraint
        dicConstraintTypes.Add "HorizontalTangent",             siHorizontalTangentConstraint
        dicConstraintTypes.Add "ExtremumHorizontalTangent",     siExtremumHorizontalTangentConstraint
        dicConstraintTypes.Add "AdjustedTangent",               siAdjustedTangentConstraint
        dicConstraintTypes.Add "ZeroLengthTangent",             siZeroLengthTangentConstraint
        dicConstraintTypes.Add "SameLengthTangent",             siSameLengthTangentConstraint
        dicConstraintTypes.Add "NeighborTangent",               siNeighborTangentConstraint
        dicConstraintTypes.Add "MirrorTangent",                 siMirrorTangentConstraint
        dicConstraintTypes.Add "AutoPlateauTangent",    siAutoPlateauTangentConstraint
        strlist = ""
        dkeys = dicConstraintTypes.Keys()
        for each k in dkeys
                if setchk = fckey.Constraint(dicConstraintTypes.Item(k)) then
                        strlist = strlist & k + " " 
                end if
        next
        GetConsList = strlist
end function
' ---------------------------------------------------------------------------------
' Create new scene
' ---------------------------------------------------------------------------------
NewScene , 0
' Create a null
set n = Application.ActiveSceneRoot.AddNull()
' Add a custompset to the null
set cpset = n.AddProperty( "Custom_parameter_list", , "CustomPSet" )
' Add a double parameter to cpset
set x = cpset.AddParameter3( "X", siDouble, 0, -100, 100, 1 )
' Create a fcurve on posx
set fc = x.AddFCurve2( array(1,0.5), siStandardFCurve )
set fckey = fc.Keys(0)
' ---------------------------------------------------------------------------------
' Set the siLockConstraint ( time, value & tangents are locked )
' ---------------------------------------------------------------------------------
' Set the Constraint property 
fckey.Constraint( siLockConstraint ) = 1
if fckey.Constraint( siLockConstraint ) then
        Application.LogMessage "fckey(" & fckey.Index & ") lock all constraints: true" 
else
        Application.LogMessage "fckey(" & fckey.Index & ") lock all constraints: false" 
end if
Application.LogMessage "fckey(" & fckey.Index & ") constraints set: " & GetConsList(fckey,true)
Application.LogMessage "fckey(" & fckey.Index & ") constraints NOT set: " & GetConsList(fckey,false)
' If you try and change the key value when the lock constraint is on it raises 
' an 'Access Denied' error.
on error resume next
fckey.Value = 5
if Err.Number then
        Application.LogMessage "fckey(" & fckey.Index & ") set value failed: " & Err.Description
end if
on error goto 0
' ---------------------------------------------------------------------------------
' Expected results::
' ---------------------------------------------------------------------------------
'INFO : fckey(0) lock all constraints: true
'INFO : fckey(0) constraints set: LockParameter LeftRightParameter G1Continuous LeftRightTangentDirection LeftRightTangentLength LockAll AutoPlateauTangent
'INFO : fckey(0) constraints NOT set: HorizontalTangent ExtremumHorizontalTangent AdjustedTangent ZeroLengthTangent SameLengthTangent NeighborTangent MirrorTangent
'INFO : 2009 - fckey(0) set value failed: Access denied

3. Python Example

# 
# This example illustrates how to create an fcurve with keys and then how to set a constraint 
# on one of the keys. 
# 
# ---------------------------------------------------------------------------------
# Functions and Setup
# ---------------------------------------------------------------------------------
# Get the Softimage constants from win32com.client and error handling from pythoncom
from win32com.client import constants as c
from pythoncom import com_error as e
constrainttypes = [ \
        (c.siParameterConstraint,                       "LockParameter"),\
        (c.siLeftRightValuesConstraint,         "LeftRightParameter"),\
        (c.siG1ContinuousConstraint,                    "G1Continuous"),\
        (c.siLeftRightTangentDirectionConstraint,       "LeftRightTangentDirection"),\
        (c.siLeftRightTangentLengthConstraint,          "LeftRightTangentLength"),\
        (c.siLockConstraint,                            "LockAll"),\
        (c.siHorizontalTangentConstraint,               "HorizontalTangent"),\
        (c.siExtremumHorizontalTangentConstraint,       "ExtremumHorizontalTangent"),\
        (c.siAdjustedTangentConstraint,                 "AdjustedTangent"),\
        (c.siZeroLengthTangentConstraint,               "ZeroLengthTangent"),\
        (c.siSameLengthTangentConstraint,               "SameLengthTangent"),\
        (c.siNeighborTangentConstraint,                 "NeighborTangent"),\
        (c.siMirrorTangentConstraint,                   "MirrorTangent"),\
        (c.siAutoPlateauTangentConstraint,              "AutoPlateauTangent") ]
def GetConsList(fckey,setchk):
        strlist = ""
        for ( c, strc ) in constrainttypes :
                if fckey.Constraint(c) == setchk:
                        strlist += strc 
                        strlist += " " 
        return strlist
# ---------------------------------------------------------------------------------
# Create new scene
# ---------------------------------------------------------------------------------
Application.NewScene("", 0)
# Create a null
null = Application.GetPrim("Null", "", "", "")
# Add a custompset to the null
cpset = null.AddProperty("Custom_parameter_list",0,"CustomPSet")
# Add a double parameter to cpset
x = cpset.AddParameter3( "X", c.siDouble, 0, -100, 100, 1 )
# Create a fcurve on posx
fc = x.AddFCurve2( [ 1, 0.5 ], c.siStandardFCurve )
fckey = fc.Keys(0)
# ---------------------------------------------------------------------------------
# Set the siLockConstraint ( time, value & tangents are locked )
# ---------------------------------------------------------------------------------
# Notice how you have to use 'SetConstraint' for the Constraint property when setting
fckey.SetConstraint(c.siLockConstraint,1)
if fckey.Constraint(c.siLockConstraint) :
        Application.LogMessage( 'fckey(%d) lock all constraints: true' % (fckey.Index) )
else :
        Application.LogMessage( 'fckey(%d) lock all constraints: false' % (fckey.Index) )
Application.LogMessage( 'fckey(%d) constraints set: %s' % (fckey.Index,GetConsList(fckey,1)))
Application.LogMessage( 'fckey(%d) constraints NOT set: %s' % (fckey.Index,GetConsList(fckey,0)))
# If you try and change the key value when the lock constraint is on it raises 
# an 'Access Denied' error.
try:
        fckey.Value = 5
except e, (hr, msg, exc, arg):
        if exc and exc[2]: msg = exc[2]
        Application.LogMessage( 'fckey(%d) set value failed: %s' % (fckey.Index,msg))
# ---------------------------------------------------------------------------------
# Expected results::
# ---------------------------------------------------------------------------------
#INFO : fckey(0) lock all constraints: true
#INFO : fckey(0) constraints set: LockParameter LeftRightParameter G1Continuous LeftRightTangentDirection LeftRightTangentLength LockAll AutoPlateauTangent
#INFO : fckey(0) constraints NOT set: HorizontalTangent ExtremumHorizontalTangent AdjustedTangent ZeroLengthTangent SameLengthTangent NeighborTangent MirrorTangent
#INFO : 2009 - fckey(0) set value failed: Access denied

See Also

FCurveKey.GetConstraint2