Bake action operator

I’m a complete noob at python, but what I want to do is use the bake action operator on multiple objects - but i’m not sure what to do. So far I have:

import bpy

lista = []
for ob in bpy.context.scene.objects:
    if ob.select:
        lista.append(ob)

for ob in lista:

I’m just not sure what to use… should it be bpy.ops.bake_action?

Thanks for any help…

try something like this, but I can think of some cases it won’t work


import bpy
scn = bpy.context.scene
sel = bpy.context.selected_objects

for ob in sel:
    scn.objects.active = ob
    bpy.ops.nla.bake(frame_start=1, frame_end=250, step=1, only_selected=True, clear_consraints=False, bake_types={'OBJECT'})

all bake parameters are defaults and not really needed unless you change something
see also there is a typo in operator: ‘clear_consraints’ should be ‘clear_constraints’ I guess…

That is very useful. Not sure if there’s a newer way to do this, but solved it for me. After fixing the typo :wink: