How to bake image without freezing ui?

Hi
I’m working on a baking addon which makes baking light map easier and so far it does the job, but it has a problem:
The blender ui freezes while baking is in progress.
So how can i bake image without freezing ui and showing default progress bar like blender does?

I’m using this for baking:

bpy.ops.object.bake_image()

Thanks.

Try
bpy.ops.object.bake_image(‘INVOKE_DEFAULT’)

Nice!
But then how can i find out when baking process is finished or cancelled?
I’ve looked into bpy.app’s persistent handlers but there is no event for baking.

Not sure if you can, does the operator call return different results on success / error?

I need to run a function after the image has been baked(i’m editing the baked image via imagemagick command).
I’ve noticed the bpy.ops.object.bake_image(‘INVOKE_DEFAULT’) returns “{RUNNING_MODAL}”. so maybe there is a way to handle this via modal or invoke method in my addon?

so far as I know, there is no way to catch the end of a generic modal operator, or the result of an operator, which, in my view, constitutes a huge design blunder.

You can however look for the event handlers in bpy.app, if they do what you want. The other way is to run a modal operator and regularly check for side-effects of the baking process (if there are any).

I’ve tried bpy.app.handlers.scene_update_post handler which gives me some chances to get when baking process is done.
Let’s say tex is my baking texture and img is my baking image, so in this handler when i press my addon bake button, i’ll get this:


print("scene_update:", tex.is_updated, img.is_updated, img.is_dirty)
# scene_update: True False True

Then scene_update_post will stop until baking process gets done, right after that i’ve got:


# scene_update: False True True
# scene_update: False False True

But i can’t get any different result on finished baking process or cancelled one. so i guess i’ll try a different approach in my addon. maybe another button to do the post bake stuff, if user will.
Thanks.

You should try a Macro, but it’s not for sure whether the operators after the call to bake_image() will wait for it to finish.