The goal is to give feedback to the user when running long blocking tasks in an addon. There is already a question with great answers from 9 years ago that should be mentioned: How to show to the user a progression in a script?
The solution suggested from ideasman42 using wm.progress_begin ist still working in Blender 3.4.1 But it would be great to give the user more specific information. Like suggested from Robin Betts i am asking this as a new question. Maybe there are some new approaches.
The info operator looks like a very clean method to me. Anyway: I am struggling to get the state updated during the script. Is it even possible to interact with the gui from within blocking code? Of course i would like to avoid unjoined threads and approaches like „bpy.ops.wm.redraw_timer(type='DRAW_WIN_SWAP', iterations=1)“
This is a minimal example of the problem and my current approach.
import bpy
from bpy.types import (Panel, Operator)
from time import sleep
operater to start the blocking job
class WM_OT_job(Operator):
bl_label = "job"
bl_idname = "wm.job"
def execute(self, context):
self.report({'INFO'}, "starting job ...") # this info is lost
for i in range(10):
text = "the current state is " + str(i)
self.report({'INFO'}, text) # this infos are lost too
sleep(0.25)
self.report({'INFO'}, "done") # this info is printed
return {"FINISHED"}
simple panel
class test(bpy.types.Panel):
"""Creates a Panel in the Object properties window"""
bl_label = "test"
bl_idname = "OBJECT_PT_custom_panel"
bl_space_type = "VIEW_3D"
bl_region_type = "UI"
bl_category = "test"
def draw(self, context):
layout = self.layout
box = layout.box()
box.operator("wm.job", text="todo")
register and unregister
def register():
bpy.utils.register_class(test)
from bpy.utils import register_class
register_class(WM_OT_job)
def unregister():
unregister_class(WM_OT_job)
from bpy.utils import unregister_class
bpy.utils.unregister_class(test)
mainloop
if name == "main":
register()