1

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.ops.anim.insert_keyframe_animall()

    bpy.data.scenes["myScene"].frame_current = end_frame
    bpy.ops.anim.insert_keyframe_animall()



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

    doEvent()
    bpy.ops.anim.insert_keyframe_animall()

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.

rien333
  • 91
  • 1
  • 10
  • 1
    Try using frame_set(x) instead of frame_current=x see this answer – sambler Nov 04 '15 at 13:18
  • 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? – rien333 Nov 05 '15 at 14:02
  • 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) – rien333 Nov 06 '15 at 19:25
  • 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. – sambler Nov 07 '15 at 11:01
  • Actually, it does change the current frame. Try it yourself maybe. – rien333 Nov 08 '15 at 21:16
  • I might be wrong in this, but while both questions were solved by the same answer (the problem lies in the same cause), the questions themselves are very different so I'm not sure wether it is appropriate to mark them as duplicates. (e.g. "What is the most sold four wheeled transportation vehicle" and "What is your prefered method of transportation for getting from your home to your work?" both can have the same answer "car", but are very different questions) – rien333 Nov 08 '15 at 21:23

0 Answers0