How to update deprecated code

I’ve got the following code in one of my scripts:

ob = Object.New('Empty','myObject')
scn.link(ob)
myIpo = Ipo.New('Object', 'myObject')
myIpo.addCurve('LocX')
myIpo[Ipo.OB_LOCX][0] = 0
myIpo[Ipo.OB_LOCX][25] = 100
ob.setIpo(myIpo)
#
xcurve = myIpo.getCurve('LocX')
xcurve.setExtrapolation('Extrapolation')
xcurve.setInterpolation('Constant')

According to the 2.42 API documentation, the methods getCurve, setExtrapolation and setInterpolation are all deprecated. The advice says:

getCurve: use the mapping opperator instead
setInterpolation: use the interpolation attribute instead
Can anyone advise me on how to do this. I’m obviously barking up the wrong tree with guestimates such as:

myIpo[Ipo.OB_LOCX].interpolation = LINEAR

(I’ve tried many more, not worth repeating here!)

Well you were awfully close :slight_smile:

You need to do either a :


import Blender

myIpo[Ipo.OB_LOCX].interpolation = Blender.IpoCurve.InterpTypes.LINEAR 
 

or


 import Blender
 from Blender.IpoCurve  import *

myIpo[Ipo.OB_LOCX].interpolation = InterpTypes.LINEAR 

I tried reducing it with :


import Blender
from Blender.IpoCurve import InterpTypes
....
myIpo[Ipo.OB_LOCX].interpolation =  LINEAR


It accepts the “import … InterpTypes”, but then gives an error on the assignment :

“LINEAR not defined”.

Mike

That error is normal. In fact, both of those have the same “shortening” effect, you have to access LINEAR through InterpTypes. The difference is that in the second one you only import InterpTypes in the main namespace while in the first one you import everything from IpoCurve.

Martin

Thanks for clearing that up.

The nearest I had got was:

myIpo[Ipo.OB_LOCX].interpolation = Blender.IpoCurve.LINEAR

Which omitted the reference to InterpTypes, so threw an error.