0
$\begingroup$

I'm trying to write a script that bakes constraints to bones. However if I select a bone via script the bpy.ops.nla.bake() operations won't run, it just returns "Nothing to bake" in the system console.

If I select a bone via the view port and then run bpy.ops.nla.bake() the bake operations works.

Both of these tests are being run in POSE mode.

  • Am I doing this wrong?
  • Is there something fundamentally different under the hood in mouse click selection?
  • Perhaps this is a bug?

To repro, create a two bone armature. (Optionally a constraint also) If anyone can help with this that would be great :)

import bpy

obj = bpy.context.object
m_bone = obj.data.bones['Bone.001']

m_bone.select = True
obj.data.bones.active = m_bone

bpy.ops.nla.bake(frame_start=0, frame_end=10, step=1, only_selected=True,
                    visual_keying=True, clear_constraints=True, clear_parents=False,
                    use_current_action=True, bake_types={'POSE'})
$\endgroup$
1
$\begingroup$

(Question duplicated from blenderartists.org. I answered it there, and am copying my answer here.)

I’ve seen that “Nothing to bake” error in 2.80 when another object is selected in addition to the armature. Try deselecting everything in Object mode, selecting the armature, re-entering Pose mode, then baking. Here is a code snippet that works for me:

scene = bpy.data.scenes[0]
arm   = bpy.data.objects['metarig']

# ensure that only the armature is selected in Object mode
bpy.ops.object.mode_set(mode='OBJECT')
bpy.ops.object.select_all(action='DESELECT')
arm.select_set(True)
scene.view_layers[0].objects.active = arm

# enter pose mode and bake
bpy.ops.object.mode_set(mode='POSE')
bpy.ops.pose.select_all(action='SELECT')
bpy.ops.nla.bake(frame_start=0, frame_end=10, step=1, only_selected=True,
                    visual_keying=True, clear_constraints=True, clear_parents=False,
                    use_current_action=True, bake_types={'POSE'})
```
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.