In GUI, it's easy this operation in Object -> Rigid Body -> Bake to keyframes. How to do that in python scripts?
I tried to write some code as below:
bpy.ops.anim.keyframe_insert(type='BUILTIN_KSI_LocRot')
bpy.ops.rigidbody.objects_remove()
bpy.ops.rigidbody.bake_to_keyframes(frame_start=1, frame_end=25)
And I got:
RuntimeError: Operator bpy.ops.anim.keyframe_insert_by_name.poll() failed, context is incorrect
Any solutions?
bpy.opsare for interactive use through the UI and should be avoided in scripts because they depend on context. Using them through scripts may yield unexpected results at best, or fail entirely at worst. Manipulate data directly frombpy.datainstead. – Duarte Farrajota Ramos Oct 21 '22 at 16:06