0
$\begingroup$

I am trying to bake particle systems from the command line. I saw this: Baking smoke on headless machine and I have been playing around with it, but I can't seem to get it to work for particles. I'm sure there is a way, but I just suck with coding like this.

$\endgroup$
0
$\begingroup$

I found this thread which had this code in it. It works perfectly fine!!

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

As you can see, this script bakes fluid, particles, and cloth. To use it, just past the code into a file, save the file as a .py python file, and then in the Blender directory type blender -b "path to .blend file" -P "path to .py file" and Blender will bake it! I hope this helps.

$\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.