Baking cloth data

Hi, I’m having a problem with baking cloth data.

I’m apparently calling bake() fromt he wrong context.

Here’s my code:


    bpy.context.scene.frame_set(i)    bpy.context.scene.objects.active = s
    bpy.ops.object.duplicate_move()
    bpy.context.area.type="PROPERTIES" 
    bpy.ops.ptcache.bake()
    bpy.context.area.type="TEXT_EDITOR"
    bpy.ops.object.convert(target='MESH', keep_original=False)

I’m just trying to duplicate a cloth and apply all of its modifiers at a certain frame. The error message I get is bpy.ops.ptcache.bake.poll() failed, context is incorrect in line 4

I tried changing the context to the properties panel, but nothing seems to do it.

Any help is welcome

Thanks.

I ended up using to_mesh() which worked much better.