Page MenuHome

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

Description

Hi,

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

FLUID_DOMAIN = 'Cube'

# Select fluid domain object
bpy.ops.object.select_name(name=FLUID_DOMAIN)
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
bpy.ops.fluid.bake()

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?

Details

Type
Bug

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:
http://blender.stackexchange.com/questions/724/bake-fluid-simulation-via-cli-or-python/728#728
and somewhat exteded it to:

import bpy

screen = bpy.context.screen
data = bpy.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 bpy.data.scenes:
    for object in scene.objects:
        for modifier in object.modifiers:
            if modifier.type == 'FLUID_SIMULATION':
                if modifier.settings.type == 'DOMAIN':
                    print ("bake: " + scene.name + " : " + object.name )
                    override = {'scene': scene, 'active_object': object, 'screen': screen, 'area' : area, 'blend_data' : blend_data, 'window' : window, 'object':object, 'region':region}
                    bpy.ops.fluid.bake(override)
                    break

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