What is the required context for the operator bpy.ops.ptcache.bake()?

This is my script so far which triggers poll failed incorrect context error:

import bpy

bpy.context.area.ui_type = 'PROPERTIES'
bpy.context.space_data.context = 'PHYSICS'

An object with a cloth modifier is active when the script is run.

I've tried to look at the source code to view the poll method but whenever I use the Edit Operator Source tool in the text editor it gives me a recursion depth error. How else can I view the code? Or maybe someone can paste it here if they're not getting the same error.


1 Answer 1


Solution using context override:

import bpy

context = bpy.context
for mod in context.object.modifiers:
    if mod.type == 'CLOTH':
        override = {blend_data: bpy.data, 'scene': context.scene, 'active_object': context.object, 'point_cache': mod.point_cache
        bpy.ops.ptcache.bake(override, 'INVOKE_DEFAULT', bake=True)

'INVOKE_DEFAULT' is required to show the bake progress bar.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .