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.
frame_set(x)instead offrame_current=xsee this answer – sambler Nov 04 '15 at 13:18frame_current = xwhen you need to useframe_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