5
$\begingroup$

I have had a look at Baking smoke on a headless machine, however, I cannot figure out my way from there to bake dynamic paint on a headless machine. This is what I have come up with by now:

import bpy

for scene in bpy.data.scenes:
    for object in scene.objects:
        for modifier in object.modifiers:
            if modifier.type == 'DYNAMIC_PAINT':
                override = {'scene': scene, 'object': object}
                bpy.ops.dpaint.bake(override)
                break

However, I get:

PyContext 'window' not found
PyContext 'window' not found
PyContext 'window' not found
Error: Bake failed: invalid canvas
Error: Bake failed: invalid canvas

Traceback (most recent call last):
  File "/home/horazont/baker.py", line 8, in <module>
    bpy.ops.dpaint.bake(override)
  File "/usr/share/blender/2.69/scripts/modules/bpy/ops.py", line 186, in __call__
    ret = op_call(self.idname_py(), C_dict, kw, C_exec, C_undo)
RuntimeError: Error: Bake failed: invalid canvas


Blender quit

Which parameters do I have to pass to the operator?

$\endgroup$
5
$\begingroup$
import bpy

obj=bpy.data.objects['Cube']
modifier=obj.modifiers['Dynamic Paint']
canvas_surface=modifier.canvas_settings.canvas_surfaces['Surface']
point_cache=canvas_surface.point_cache

context={}
context['blend_data']=bpy.data
context['scene']=bpy.data.scenes['Scene']
context['active_object']=obj
context['point_cache']=point_cache

bpy.ops.ptcache.bake(context,bake=True)

Objects can be both a brush and a canvas. The baking is done by the surfaces of the canvas. So an additional iteration is necessary.

#...
for modifier in obj.modifiers:
    if modifier.type=='DYNAMIC_PAINT':
        #additional iteration
        for canvas_surface in modifier.canvas_settings.canvas_surfaces:
             context['active_object']=obj
             context['point_cache']=canvas_surface.point_cache
             bpy.ops.ptcache.bake(context,bake=True)
$\endgroup$
  • $\begingroup$ Made an edit. modifier.ui_type is used by the user interface to remember the state of the tab and does not indicate wether the object is a brush or a canvas. in fact it can be both. $\endgroup$ – pink vertex Feb 4 '14 at 15:44
  • $\begingroup$ This doesn’t seem to work for image sequences. Any clues? $\endgroup$ – Jonas Schäfer Sep 5 '16 at 20:45

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.