0

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' bpy.ops.ptcache.bake(bake=True)

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.

hilifit
  • 192
  • 8

1 Answers1

0

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) break

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

hilifit
  • 192
  • 8