Find all relevant FCurve information

Some days ago, I had an interesting problem. I needed to find all relevant FCurve information (keys+bézier-points). Here is a example that finds all keys, bézier-tangent-information and the keytypes for the TranslateX Axis of the selected object. Quite cool is, that it gives the exact time and value for the tangents – what disciples the fcurve the best way. It also works with related values.

from win32com.client import constants as c
xsi = Application
log = Application.LogMessage

# Convenience function to get the user-friendly string describing the contraint type
def GetConstraintType( in_fcrvkey ) :
        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"
        }
        str = ""
        for k in ConstraintTypes.keys() :
                if ( in_fcrvkey.Constraint(k) ) :
                        str += ConstraintTypes[k] + " "
        return str

# Convenience function to print the FCurveKeys
def PrintKeys( in_fcrv ) :
        for fckey in in_fcrv.Keys :
				log("------------------------------------------------------")
				log("key\t\t:\t" + str(fckey.Index))
				log("frame\t\t:\t" + str(fckey.Time))
				log("value\t\t:\t" + str(fckey.Value))		
				log("tangents:\t\t" + str(fckey.LeftTanX) + " | " + str(fckey.LeftTanY) +  " | " + str(fckey.RightTanX) + " | " + str(fckey.RightTanY))	
				log("constraints\t:\t" + str(GetConstraintType( fckey )))		
        return None

fc = xsi.Selection[0].posx.Source

if fc:
	if fc.type == "Expression":
		fc_Expression = fc.Parameters[4].Source
		log(fc_Expression.Keys.Count	)
		PrintKeys( fc_Expression )
	else:
		log(fc.Keys.Count)
		PrintKeys( fc )
else:
	log("No Key!")

Welcome!

Hey, this is my fist entry. I hope I can stay posting interesting articles about my work. Stay tuned. I’m looking forward to your comments.