I try to write a tool to bake all IK keys of a rigify armature to FK keys
Basically, I use the IK to FK function, I create a rotation key on FK bones, and I move to next keyframe. Easy!
It works with the current frame, but when I need to iterate between keyframes, the 3d view doesn’t refresh, and all FK keys are the same. If only I could refresh the view, I feel it would solve my issue. But no way…
this my code :
import bpy
lastkey = -10
bpy.context.scene.frame_set(0)
while bpy.context.scene.frame_current > lastkey:
lastkey = bpy.context.scene.frame_current
#fk2ik function
bpy.ops.pose.rigify_arm_fk2ik_z0gi8z8u886b3215(uarm_fk="upper_arm.L", farm_fk="forearm.L", hand_fk="hand.L", uarm_ik="MCH-upper_arm_ik.L", farm_ik="MCH-forearm_ik.L", hand_ik="hand_ik.L")
# big mess to try to update the scene, but visually, it don't works
bpy.context.scene.update()
bpy.data.scenes[0].update()
bpy.context.scene.frame_set(lastkey)
# insert keys on FK bones, it works great if I stay at current time
bpy.context.active_object.keyframe_insert(data_path='pose.bones["forearm.L"].rotation_euler')
bpy.context.active_object.keyframe_insert(data_path='pose.bones["upper_arm.L"].rotation_quaternion')
bpy.context.active_object.keyframe_insert(data_path='pose.bones["hand.L"].rotation_quaternion')
#move to next keyframe
bpy.ops.screen.keyframe_jump()