Page MenuHome

No way to control fluid simulator from Python API?
Closed, ResolvedPublic



I'm trying to get a Python script together to make it possible to bake a fluid sim from the command-line, as I'd like to run the baking on a remote system, where there is more CPU power available. However, it seems the Python API doesn't fully allow control of the baking. So far, I have:

import bpy


# Select fluid domain object
assert len(bpy.context.selected_objects) == 1

fluid_domain = bpy.context.selected_objects[0]

assert len(fluid_domain.modifiers) == 1
fluid_sim_modifier = fluid_domain.modifiers[0]

fluid_sim_settings = fluid_sim_modifier.settings
fluid_sim_settings.resolution = 100
fluid_sim_settings.preview_resolution = 50
fluid_sim_settings.filepath = '//baked_fluid/'

# XXX this call returns immediately, while the simulation itself
# run in separate threads. Eeek

The problem lies in not being able to detect when the baking is done. I can only find the Python equivalent of pressing the bake button, but, as noted in a different bug report, this only starts the simulator in the background, so the bake() call returns immediately.

Is there a Python way to get the status of the sim, and wait for it to finish?



Event Timeline

Most operators were coded for UI usage first. You could check this by making a script that runs in the UI fine.

Allowing this to run in the background is of course very useful, but afaik we had other ways to do it? Campbell knows.

fixed r40642.
Calling the operator from python now blocks until its done, but not from the ui - same as texture bake.

For 2.69 and 2.70a it looks as if it's back again.
(windows only:)
System: Win 8.1 64 bit
PYTHON INTERACTIVE CONSOLE 3.3.0 (default, Nov 26 2012, 15:38:36) [MSC v.1500 64 bit (AMD64)]
i5-3210M 2.5 GHz
(on linux, it's running ok)

Even tried th solution suggested by brecht from here:
and somewhat exteded it to:

import bpy

screen = bpy.context.screen
data =
area = bpy.context.area
blend_data = bpy.context.blend_data
screen = bpy.context.screen
window = bpy.context.window
object = bpy.context.object
region = bpy.context.region

for scene in
    for object in scene.objects:
        for modifier in object.modifiers:
            if modifier.type == 'FLUID_SIMULATION':
                if modifier.settings.type == 'DOMAIN':
                    print ("bake: " + + " : " + )
                    override = {'scene': scene, 'active_object': object, 'screen': screen, 'area' : area, 'blend_data' : blend_data, 'window' : window, 'object':object, 'region':region}

print ('baking done.')

regards, F99

Thanks for confirming.
I guess it's a point where the process forks to bake.
There win and linux could behave differently about the return value, which would explain it all.
regards, F99