Insert new Keys into existing IpoCurve

I’m trying to edit an existing “LocY” IpoCurve in Blender 2.36 within a python script. The curve already has points (keyframes) set on frame 0 and let’s say frame 10. Example:

IpoCurve Point 0: [0, 1000]
IpoCurve Point 1: [10, 900]

Now I’m trying to insert a new key on frame 5 with a value of let’s say ‘100’:

object = Blender.Object.Get( "test" )
ipo = object.getIpo()
curve = ipo.getCurve( "LocY" )
curve.addBezier( 5, 100 )

This works but then there are strange things happening :slight_smile: The new point has been appended to the existing points:

IpoCurve Point 0: [0, 1000]
IpoCurve Point 1: [10, 900]
IpoCurve Point 2: [5, 100]

But what I want is:

IpoCurve Point 0: [0, 1000]
IpoCurve Point 1: [5, 100]
IpoCurve Point 2: [10, 900]

Any ideas?

Thanks a lot!

Strange: When I save my .blend file and reopen it, the keys are sorted right! It’s like I’m missing something or doing completly wrong?

Or is this a bug?

Any ideas?

Thanks!

This might be totally off the mark, but could it have anything to do with the (re)draw command?

I had the same thing, all messed up wires.
.redraw() nor .update() fixes this.
Going into the curves with TAB-TAB does fix it, but thats the worst possible solution, except saving and loading the file, what is new to me.

I read there is going to be a new function, insertIpoKey() or something, maybe that might do the trick? But that’s only for LOC ROT (and SIZ?)

TAB-TAB is possible with python.
Just have a look at this similar post of jms: https://blenderartists.org/forum/viewtopic.php?t=41977

Yes, I can put keys in the blender Que. But then I’d also need to select the object and the objects IPO etc. Very ugly bugly :slight_smile:

I can’t do anything but agree with you on that. But unfortunately I don’t know any other solution at the moment either. :frowning: So, unless some people who have a better knowledge of python than me (and there are a lot of them), think of an alternative way, we’ll have to wait for that new function you mentioned.

I read in the BF commiters list that somebody is working on insertIpo() so a little patience might help us out.

Well, I’ve hoped that 2.37 would bring a workaround for the IPO editing problem but I can’t find it :x

There’s the new “Delete” method to remove a control point from the curve but the “insert” is IMHO still appending points :expressionless:

Well, I could now delete all control points and then append (insert) them all together again with my new control point at the right index but this really seems silly to me :wink: and I’ve not tried that yet… 8)

Any ideas? Something else in 2.37 that I’m missing? :expressionless: