1
$\begingroup$

While baking from GUI perfectly works, I have no animation if baked using the script below.

pic

What else could I try?

sudo blender --background fluid.blend --python bake.py

cat bake.py

import bpy

for scene in bpy.data.scenes:
    for object in scene.objects:
        for modifier in object.modifiers:
            if modifier.type == 'FLUID':
                if modifier.fluid_type == 'DOMAIN':
                    print("Baking fluid")
                    object.select_set(True)
                    bpy.context.view_layer.objects.active = object
                    bpy.ops.fluid.bake_data()
            elif modifier.type == 'CLOTH':
                print("Baking cloth")
                override = {'scene': scene, 'active_object': object, 'point_cache': modifier.point_cache}
                bpy.ops.ptcache.free_bake(override)
                bpy.ops.ptcache.bake(override, bake=True)
            elif modifier.type == 'PARTICLE_SYSTEM':
                print("Baking particles")
                override = {'scene': scene, 'active_object': object, 'point_cache': modifier.particle_system.point_cache}
                bpy.ops.ptcache.free_bake(override)
                bpy.ops.ptcache.bake(override, bake=True)
bpy.ops.wm.save_mainfile()

Log:

Blender 2.92.0 (hash 02948a2cab44 built 2021-04-25 11:39:34)
Read prefs: /root/.config/blender/2.92/config/userpref.blend
Read blend: /home/user/tmp/fluid.blend
Baking fluid
Info: Fluid: Bake Data complete! (0.32)
Baking particles
Info: Saved "fluid.blend"
Info: Saved "fluid.blend"
$\endgroup$
0
$\begingroup$

this works for me:

if modifier.type == 'FLUID':
    if modifier.fluid_type == 'DOMAIN':
                    print("baking fluid %s %s"%(modifier.type, object.name))
                    override = {'scene': scene, 'active_object': object, 'point_cache': modifier.domain_settings.point_cache}
                    bpy.ops.ptcache.free_bake_all()
                    bpy.ops.ptcache.bake_all(bake=True)
                    
$\endgroup$

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.