I'm trying to write a script that does some animation task for me. The keyframes in this in this animation are created using the build-in "animall" add on. Animall animates some transformations on the surface of an object. The animation consist of repeatedly going through this process:

default state -> generate some transformations with animall -> back to the default state
(repeat for the next set of frames)

The code I use to accomplish the animation boils down to this:

for frame in range(0, max_amount_of_frames, frames_per_event):
    # "+ 1" to keep all the events split, not sure if it's needed though 
    animate_event(frame + 1, frame+frames_per_event)

def animate_event(start_frame, end_frame):

    # Create the default states
    bpy.data.scenes["myScene"].frame_current = start_frame

    bpy.data.scenes["myScene"].frame_current = end_frame

    # Do the event
    mid_frame = int(start_frame + (end_frame - start_frame)/2)
    bpy.data.scenes["myScene"].frame_current = mid_frame


This works for the first iteration, but on the other ones Blender copies the properties of the last added keyframe (in this case the generation event) to the newly inserted keyframe. (so the first added keyframe of the second iteration becomes the last added keyframe of first iteration, instead of the default state) The weird part is that Blender only does this if I run my script, but not when I perform the process manually. Why does Blender behave like this? How can I fix it? Suggestions for another methodology for my animation task are also welcome.

  • 1
    $\begingroup$ Try using frame_set(x) instead of frame_current=x see this answer $\endgroup$
    – sambler
    Nov 4, 2015 at 13:18
  • $\begingroup$ Thank you, this totally fixed it. I find it pretty weird though that my previous incorrect method with the getter seems to have the same behavior (with all the keyframes being inserted on the right frames), but created a very different animation. Can you maybe post this in an answer so I can mark the question as answered? $\endgroup$
    – rien333
    Nov 5, 2015 at 14:02
  • $\begingroup$ Possible duplicate of Render specific frames with opengl via python $\endgroup$
    – sambler
    Nov 6, 2015 at 17:13
  • $\begingroup$ Could you explain to me why this is a duplicate question? I see how we make the same mistake, but our goals and problem descriptions are very different. (I might be wrong in this though) $\endgroup$
    – rien333
    Nov 6, 2015 at 19:25
  • $\begingroup$ The cause of both issues is trying to change the current frame using frame_current = x when you need to use frame_set(x). This boils down to the current frame not being changed which messes up further steps, whether you are rendering an animation or creating keyframes, both break when the current frame is not set correctly. $\endgroup$
    – sambler
    Nov 7, 2015 at 11:01


You must log in to answer this question.

Browse other questions tagged .