When I call an existing operator in the execute function of another operator I have created, the self.report from the existing operator is not triggered. Is there a way to enable this, or access the reports of the existing operator somehow so they can be called by my operator?
1 Answer
$\begingroup$
$\endgroup$
4
Test success version: v2.92, v2.93
Test failed version: v3.3 (I hope someone can explain that)
- Run script and call the operator from search menu : xx
- Make sure you have an object selected and the report is: Deleted 1 object(s)
import bpy
import io
from contextlib import redirect_stdout
stdout = io.StringIO()
def catch_report(fn): # not catch error
with redirect_stdout(stdout):
fn()
stdout.seek(0)
return stdout.read()
class XX(bpy.types.Operator):
bl_idname = "xx.operator"
bl_label = "XX"
def execute(self, context):
def fn():
bpy.ops.object.delete(use_global=False, confirm=False)
tx = catch_report(fn)
if tx:
tx = tx[:-1]
print(tx)
self.report({'INFO'}, tx)
return {'FINISHED'}
def register():
bpy.utils.register_class(XX)
def unregister():
bpy.utils.unregister_class(XX)
if __name__ == "__main__":
register()
-
$\begingroup$ This doesn't work for me. This is how I tried it: 1)Add Cube to scene 2)Paste code into text editor and run 3)Select Cube and delete using xx operator from search menu. There's no report. If I delete the cube normally there is a report. $\endgroup$– hilifitOct 6, 2022 at 16:52
-
$\begingroup$ Are you a Mac user? I tested on window11, it works on blender 2.92. $\endgroup$– X YOct 6, 2022 at 17:17
-
-
$\begingroup$ I tested v3.3 the
catch_report
function doesn't work and the operator cannot register on the search menu. Some api seems to have changed on v3.3 $\endgroup$– X YOct 7, 2022 at 2:02