I think I'll have to start paying you soon :P
Thanks!
----- Original Message -----
From: Bernard Lebel
To: XSI(at)Softimage.COM
Sent: Tuesday, July 17, 2007 5:18 PM
Subject: Re: [scripting] exporting keys
Here's the code that I used to use to write fcurves to XML. This is part of a larger framework, so don't worry if you feel like there's code missing.
Should get you started. You don't need any command, the object model provides everything you need for that.
def writeFcurve( self, oParameter, iSpace ):
"""
Write the override entry type as a parameter.
"""
self.aFileLines.append(
' '.join( [
'%s<parameter' % ( ' ' * iSpace, ),
'scriptname="%s"' % ( oParameter.scriptname, ),
'valuetype="%i"' % ( oParameter.valuetype, ),
'sourceclassname="FCurve"',
'inputid="0"',
'entrytype="2">\n'
] )
)
# Get the fcurve
oFcurve = oParameter.source
# Check if fcurve has keyframes
if oFcurve.keys.count > 0:
iSpace2 = iSpace + 2
self.aFileLines.append( '%s%s<fcurve plotted="%s">' % ( '\n', ' ' * iSpace2, str(bPlotted) ) )
iSpace4 = iSpace2 + 2
self.aFileLines.append ( '%s<fcurveparameter scriptname="extrapolation" valuetype="2">%i</fcurveparameter>\n' % ( ' ' * iSpace4, oFcurve.extrapolation ) )
self.aFileLines.append( '%s<fcurveparameter scriptname="interpolation" valuetype="2">%i</fcurveparameter>\n' % ( ' ' * iSpace4, oFcurve.interpolation ) )
self.aFileLines.append( '%s<fcurveparameter scriptname="highclamp" valuetype="5">%f</fcurveparameter>\n' % ( ' ' * iSpace4, oFcurve.highclamp ) )
self.aFileLines.append( '%s<fcurveparameter scriptname="lowclamp" valuetype="5">%f</fcurveparameter>\n' % ( ' ' * iSpace4, oFcurve.lowclamp ) )
self.aFileLines.append( '%s<fcurveparameter scriptname="nokeyvalue" valuetype="4">%f</fcurveparameter>\n' % ( ' ' * iSpace4, oFcurve.nokeyvalue ) )
for oKeyframe in oFcurve.keys:
self.writeKeyframe( oKeyframe, iSpace4 )
self.aFileLines.append( '%s</fcurve>\n' % ( ' ' * iSpace2 ) )
self.aFileLines.append( '%s</parameter>\n' % ( ' ' * iSpace, ) )
def writeKeyframe( self, oKeyframe, iSpace ):
# Because of inconsistencies in float precision,
# We have to round the time
self.aFileLines.append( '%s<keyframe time="%f" value="%f">\n' % ( ' ' * iSpace, round(oKeyframe.Time), oKeyframe.Value ) )
iSpace2 = iSpace + 2
self.aFileLines.append( '%s<keyconstraint type="1" valuetype="11">%s</keyconstraint>\n' % ( ' ' * iSpace2, str(oKeyframe.Constraint( 1 )) ) )
self.aFileLines.append ( '%s<keyconstraint type="2" valuetype="11">%s</keyconstraint>\n' % ( ' ' * iSpace2, str(oKeyframe.Constraint( 2 )) ) )
self.aFileLines.append( '%s<keyconstraint type="4" valuetype="11">%s</keyconstraint>\n' % ( ' ' * iSpace2, str( oKeyframe.Constraint( 4 )) ) )
self.aFileLines.append( '%s<keyconstraint type="8" valuetype="11">%s</keyconstraint>\n' % ( ' ' * iSpace2, str(oKeyframe.Constraint( 8 )) ) )
self.aFileLines.append( '%s<keyconstraint type="16" valuetype="11">%s</keyconstraint>\n' % ( ' ' * iSpace2, str(oKeyframe.Constraint( 16 )) ) )
self.aFileLines.append ( '%s<keyconstraint type="32" valuetype="11">%s</keyconstraint>\n' % ( ' ' * iSpace2, str(oKeyframe.Constraint( 32 )) ) )
self.aFileLines.append( '%s<keyconstraint type="65" valuetype="11">%s</keyconstraint>\n' % ( ' ' * iSpace2, str( oKeyframe.Constraint( 64 )) ) )
self.aFileLines.append( '%s<keyconstraint type="128" valuetype="11">%s</keyconstraint>\n' % ( ' ' * iSpace2, str(oKeyframe.Constraint( 128 )) ) )
self.aFileLines.append( '%s<keyconstraint type="256" valuetype="11">%s</keyconstraint>\n' % ( ' ' * iSpace2, str(oKeyframe.Constraint( 256 )) ) )
self.aFileLines.append ( '%s<keyconstraint type="512" valuetype="11">%s</keyconstraint>\n' % ( ' ' * iSpace2, str(oKeyframe.Constraint( 512 )) ) )
self.aFileLines.append( '%s<keyconstraint type="1024" valuetype="11">%s</keyconstraint>\n' % ( ' ' * iSpace2, str( oKeyframe.Constraint( 1024 )) ) )
self.aFileLines.append( '%s<keyproperty type="interpolation" valuetype="2">%i</keyproperty>\n' % ( ' ' * iSpace2, oKeyframe.Interpolation ) )
self.aFileLines.append( '%s<keyproperty type="left" valuetype="4">%f</keyproperty>\n' % ( ' ' * iSpace2, oKeyframe.Left ) )
self.aFileLines.append( '%s<keyproperty type="right" valuetype="4">%f</keyproperty>\n' % ( ' ' * iSpace2, oKeyframe.Right ) )
self.aFileLines.append( '%s<keyproperty type="lefttanx" valuetype="4">%f</keyproperty>\n' % ( ' ' * iSpace2, oKeyframe.LeftTanX ) )
self.aFileLines.append ( '%s<keyproperty type="lefttany" valuetype="4">%f</keyproperty>\n' % ( ' ' * iSpace2, oKeyframe.LeftTanY ) )
self.aFileLines.append( '%s<keyproperty type="righttanx" valuetype="4">%f</keyproperty>\n' % ( ' ' * iSpace2, oKeyframe.RightTanX ) )
self.aFileLines.append( '%s<keyproperty type="righttany" valuetype="4">%f</keyproperty>\n' % ( ' ' * iSpace2, oKeyframe.RightTanY ) )
self.aFileLines.append( '%s</keyframe>\n' % ( ' ' * iSpace, ) )
On 7/17/07, Alexander Hemery < vortex(at)fhw.gr> wrote:
>
>
> hello all
>
> I want to make a script that exports plotted transformations of a selected
> object to a file where each line represents a keyframe and has
> posXYZ/rotXYZ/sclXYZ values.
> What commands should I be looking for ? I have no idea where to start.
> Thanks in advance!
>
> Alex.
>