Summary
When an operator is run multiple times successively in blender, report messages (generated by report() API) from previous runs are also showing up in present run.
What is the reason behind it and how to address it properly?
Example code
import bpy
class ReporQueueNotClearedOperator(bpy.types.Operator):
bl_idname = "object.report_queue_not_cleared"
bl_label = "Test Report Queue"
def execute(self, context):
if len(context.selected_objects) == 0:
self.report(
{"ERROR_INVALID_INPUT"},
"No object is selected. Cancelling!",
)
return {"CANCELLED"}
if len(bpy.data.materials) == 0:
self.report(
{"ERROR"},
"There are no materials in the scene. Not executing!",
)
return {"CANCELLED"}
self.report(
{"INFO"},
"There are materials in the scene. Executing!",
)
return {'FINISHED'}
# Register the operator
def menu_func(self, _context):
layout = self.layout
layout.separator()
layout.operator(
ReporQueueNotClearedOperator.bl_idname,
text=ReporQueueNotClearedOperator.bl_label,
)
def register():
bpy.utils.register_class(ReporQueueNotClearedOperator)
bpy.types.VIEW3D_MT_add.append(menu_func)
def unregister():
bpy.types.VIEW3D_MT_add.remove(menu_func)
bpy.utils.unregister_class(ReporQueueNotClearedOperator)
if __name__ == "__main__":
register()
Reproduction steps
- Open Blender (I’m using Blender 4.3.2 in Windows 11).
- Copy-paste the above code and execute the operator from Text Editor window.
- Come to 3D Viewport window. Make sure no object is selected.
- Click
Add
>Test Report Queue
. - Select the
Cube
object. - Click
Add
>Test Report Queue
. - Remove all the materials using following code in Python Console window.
for mat in bpy.data.materials:
bpy.data.materials.remove(mat)
- Come to 3D Viewport window. Select the
Cube
object. - Click
Add
>Test Report Queue
. - Repeat step 3.
- Click
Add
>Test Report Queue
.
Observation
After step 4
Expected and Actual message - No object is selected. Cancelling!
After step 6
Expected and Actual message - There are materials in the scene. Executing!
After step 9
Expected and Actual message - There are no materials in the scene. Not executing!
After step 11
Expected message - No object is selected. Cancelling!
Actual message - Along with No object is selected. Cancelling!
, There are no materials in the scene. Not executing!
log also appears on the status bar.
Inference
It looks like some instance of earlier reports are still present in report queue. I searched for clear/flush APIs/methods for report queue, but could not find any suitable answer.
I am not even sure if they indeed are maintained in a queue fashion. Please help!