14

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?

GiantCowFilms
  • 18,710
  • 10
  • 76
  • 138
Robberbob
  • 143
  • 1
  • 5
  • 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: https://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. –  May 09 '14 at 11:08
  • 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 –  Apr 16 '15 at 03:59
  • Works fine for me.. Is it possible you could upload a file where it doesn't work? – gandalf3 Apr 16 '15 at 04:07
  • How do I upload a file here? –  Apr 16 '15 at 04:11
  • 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 – gandalf3 Apr 16 '15 at 04:14
  • Cool!!!

    Here:

    –  Apr 16 '15 at 04:16
  • I also tried modifying the script based on a solution for baking smoke simulation in CL, found here: http://blender.stackexchange.com/questions/4963/baking-smoke-on-headless-machine

    this 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
  • It works fine for me... It spits out a bunch of errors like you describe, but it still bakes – gandalf3 Apr 16 '15 at 04:25
  • oh... funny... ok, I will try again –  Apr 16 '15 at 04:32

2 Answers2

25

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
brecht
  • 7,471
  • 30
  • 48
2

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)
Hugh Perkins
  • 143
  • 8