admin管理员组文章数量:1404571
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.
Issue image
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!
本文标签:
版权声明:本文标题:python - Blender: Report message from previous run persists in successive run of the same operator - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744802400a2625942.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论