I would like to run a fluid simulation on a headless Ubuntu machine I have lying around. I did manage to find a bug report on the issue but to no avail. Has anyone else had any success? Or perhaps a better solution to my problem?
2 Answers
It's a bit more complicated than it could be because fluid simulating baking is only exposed as an operator. That means it expects an active object in the context, which is usually provided by the user interface that is not available in background mode.
It is possible to pass this object to the operator manually however. The following is an example script that bakes all fluid domain objects in all scenes:
import bpy
for scene in bpy.data.scenes:
for object in scene.objects:
for modifier in object.modifiers:
if modifier.type == 'FLUID_SIMULATION':
if modifier.settings.type == 'DOMAIN':
bpy.ops.fluid.bake({'scene': scene, 'active_object': object})
break
This works when executed from the command line with a command like this:
blender --background file.blend --python script.py
- 7,471
- 30
- 48
-
Just out of curiosity, are you Brecht van Lommel, the Cycle Developer? – Quazi Irfan Jun 10 '13 at 05:17
-
11
-
This answer just made my day - only the co-producer of Blender could figure out how to bake fluids. – Cheshire Cat Aug 22 '15 at 17:54
-
1Does this mean we can in fact bake multiple domains with one command? The UI complains when there are multiple domain objects – Nino van Hooff Nov 05 '17 at 00:17
In Blender 4.0.2, I hunted around for a while. The bake function, from Brecht's answer above, complained about 1-2 args, and I didn't know how to solve that. Here's what works for me:
Create a script bake_fluids.py, like:
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...')
object.select_set(True)
bpy.context.view_layer.objects.active = object
bpy.ops.fluid.bake_all()
bpy.ops.wm.save_mainfile()
Then run it like:
/Applications/Blender.app/Contents/MacOS/Blender \
--background \
~/BlenderFiles/test_render1.blend \
--python bake_fluids.py
Notes:
- change the path to blend file to your own blend file
- If you're not on Mac, use the Windows or Linux path to Blender executable, as appropriate, e.g. simply
blender, on Ubuntu, perhaps)
- 143
- 8
Here:
– Apr 16 '15 at 04:16this is how i modified Brecht's script
import bpy
for scene in bpy.data.scenes: for object in scene.objects: for modifier in object.modifiers: if modifier.type == 'FLUID_SIMULATION': if modifier.settings.type == 'DOMAIN': override = {'scene': scene, 'active_object': object, 'point_cache': modifier.domain_settings.point_cache} bpy.ops.fluid.bake(override, bake=True) break
– Apr 16 '15 at 04:19