14
$\begingroup$

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?

$\endgroup$
9
  • $\begingroup$ Seems not to work for 2.69 and 2.70a. Only an issue on Windows 8.1 (64bit i5 mobile) No Problem on Linux (Ubuntu 12 and 14) Posted a comment here: developer.blender.org/T28725 regards, F99 (edit:) ok, the essence of the post is, the operator bpy.ops.fluid.bake() is simply not working. It returns "finished", but the bake is NOT started at all. $\endgroup$
    – user3423
    Commented May 9, 2014 at 11:08
  • $\begingroup$ I am trying Brecth's method, but failed with a continuous series of errors that read as below: PyContext 'screen' not found PyContext 'screen' not found PyContext 'area' not found PyContext 'blend_data' not found PyContext 'region' not found PyContext 'area' not found It seems that I need to indicate what is the "active object", then "scene" and so on... Did anyone manage to perform a simulation via the command line? Thanks, Diego $\endgroup$
    – user13796
    Commented Apr 16, 2015 at 3:59
  • $\begingroup$ Works fine for me.. Is it possible you could upload a file where it doesn't work? $\endgroup$
    – gandalf3
    Commented Apr 16, 2015 at 4:07
  • $\begingroup$ How do I upload a file here? $\endgroup$
    – user13796
    Commented Apr 16, 2015 at 4:11
  • $\begingroup$ You can't upload .blends directly to SE at this time, but pasteall is a good blender-specific option for temporary usage. For more permanent storage, there's blend-exchange $\endgroup$
    – gandalf3
    Commented Apr 16, 2015 at 4:14

2 Answers 2

25
$\begingroup$

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
$\endgroup$
4
  • $\begingroup$ Just out of curiosity, are you Brecht van Lommel, the Cycle Developer? $\endgroup$ Commented Jun 10, 2013 at 5:17
  • 11
    $\begingroup$ Yes, that's me. $\endgroup$
    – brecht
    Commented Jun 10, 2013 at 18:12
  • $\begingroup$ This answer just made my day - only the co-producer of Blender could figure out how to bake fluids. $\endgroup$ Commented Aug 22, 2015 at 17:54
  • 1
    $\begingroup$ Does this mean we can in fact bake multiple domains with one command? The UI complains when there are multiple domain objects $\endgroup$ Commented Nov 5, 2017 at 0:17
2
$\begingroup$

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)
$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .