So I’ve recently been working on a tool that will allow simple and easy importing of cache data from Maya in to Softimage. Basically, baked animation from fbx files copy/pasted to models within my Softimage scene. Having completed a first draft of the tool it was then suggested that the imported animation curves be converted from Spline interpolation into Linear interpolation. Oddly enough it proved a little more difficult to understand how to access the fcurve interpolation than I’d first thought.
First off I nipped into the SDK to see what it had to say and to be honest it all seemed easy enough. So to test I could access the fcurves interpolation I wrote this little script:
import win32com from win32com.client import constants as c xsi = Application selection = tuple(xsi.Selection) for eachObj in selection: for eachParam in item.NodeAnimatedParameters (c.siAnySource): print eachParam.Interpolation
..but it threw up this error.
# ERROR : Traceback (most recent call last):
#Â Â File “<Script Block >”, line 9, in <module>
#Â Â Â Â print eachParam.Interpolation
#Â Â File “C:\Program Files\Autodesk\Softimage 2013 SP1\Application\python\Lib\site-packages\win32com\client\dynamic.py”, line 500, in __getattr__
#Â Â Â Â raise AttributeError, “%s.%s” % (self._username_, attr)
# AttributeError: <unknown>.Interpolation
#Â – [line 9]
So off to Google I went and upon spending a little time googling I came across this blog by phil meloncon which had a post that appeared to foot the bill. http://philmelancon.wordpress.com/2012/01/21/fcurves-interpolation/
What phil’s little tool does (or will do) is allow you toÂ change the interpolation of the selected objects fcurves based on whether you run the script as-is or with ctrl or alt held. So I grabbed this script and slapped it into Softimage to give it a whirl and see if I could hack it up to do what I wanted. So I selected my object rand the script….. no dice. The same error! Interesting.
More interestingly was that someone has commented on phil’s script saying they had returned the same error I was getting. So I looked a little bit further.
What I didn’t seem to realise was that in order to access fCurves interpolation there is another level of parameters that need to be interrogated in order for the interpolation to be accessed – more specifically the fCurves. Currently as the script stands, it is only looking at the parameters for posx. posy etc and not their fCurves. So another loop was needed in order to extract the fCurves source in order to access the interpolation values. This can be done by using the “GetSource” command.
So if we just tweak our code to contain a further loop (accessing the fCurves) we can then get their interpolation values.
import win32com from win32com.client import constants as c xsi = Application selection = tuple(xsi.Selection) for eachObj in selection: for eachParam in eachObj.NodeAnimatedParameters (c.siAnySource): source = xsi.GetSource (eachParam, c.siFCurveSource) for fcurve in source: print fcurve.Interpolation