0

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.

Chris
  • 59,454
  • 6
  • 30
  • 84
Abnormal
  • 46
  • 4

1 Answers1

1

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.

Abnormal
  • 46
  • 4