I wonder if it is currently possible to print or send messages to the Report window in the Info view? this would be quite useful sometimes.
3 Answers
We can always use an operator's report
method. Running the following operator:
class RENDER_OT_test(bpy.types.Operator):
bl_idname = 'render.oha_test'
bl_label = 'Test'
bl_options = {'REGISTER', 'UNDO'}
def execute(self, context):
self.report({'INFO'}, 'Printing report to Info window.')
return {'FINISHED'}
prints this in the Info window:
The color depends on the type enum: INFO
gets green, WARNING
light red, and ERROR
dark red. I don't see reference to any direct output to Info window, other than this method.
-
2$\begingroup$ i made this snippet to demo a problem i've experienced: gist.github.com/zeffii/5734884 , say I try to call this operator from a place in a script using
bpy.ops.render.oha_test()
i getUndefined Type: Printing report to Info window. {'FINISHED'}
and there is no printing to the report window.. $\endgroup$– zeffiiJun 8, 2013 at 11:33 -
1$\begingroup$ When the enumeration type is only
INFO
,WARNING
orERROR
, the message is prefixed accordingly (e.g. "Info: ...
"). But if we addDEBUG
, the prefix turns to "Undefined Type: ...
". Maybe we're dealing with a little quirk (bug?) in the C function related to flag-reading. Gotta read the source to make sure, but I don't think it's an error. (andreport
doesn't output to report area if executed on a Python interpreter area) $\endgroup$– AdhiJun 8, 2013 at 11:57 -
2$\begingroup$ I don't know if combinations should be allowed, but they were not really intended in the design, so maybe something should be fixed in Blender. That's why I suggest to change the example to use only 1 value. $\endgroup$– brechtJun 8, 2013 at 12:19
-
2$\begingroup$ I tried the sample but I cant get message in the info view..
import bpy class RENDER_OT_test(bpy.types.Operator): bl_idname = 'render.oha1_test' bl_label = 'Test' bl_options = {'REGISTER', 'UNDO'} def execute(self, context): self.report({'INFO'}, 'Printing report to Info window.') return {'FINISHED'} bpy.utils.register_class(RENDER_OT_test)
# test call to the newly defined operatorbpy.ops.render.oha1_test()
$\endgroup$– user918Jul 9, 2013 at 4:13 -
2$\begingroup$ After running the script, execute the operator as
bpy.ops.render.oha1_test
in Python console or as Test in spacebar-menu. Works for me. $\endgroup$– AdhiJul 9, 2013 at 5:16
I needed to display a notification message when running a script in the Text Editor by hitting the 'Run Script' button. For exactly this purpose I have found a hack that works, even if this is not the preferred way :)
import bpy
def oops(self, context):
self.layout.label(text="You have done something you shouldn't do!")
bpy.context.window_manager.popup_menu(oops, title="Error", icon='ERROR')
-
$\begingroup$ with newer version of blender 2.9x use self.layout.label(text="You have done something you shouldn't do!") $\endgroup$– cschollFeb 15, 2021 at 10:48
This should be the code: to get popup in mouse event use ERROR instead INFO. see report -'INFO' is lower and 'ERROR_OUT_OF_MEMORY' is highest level of error type.
def yourfunction(context):
whatever the function
class RENDER_OT_test(bpy.types.Operator):
bl_idname = 'render.oha_test'
bl_label = 'Test'
bl_options = {'REGISTER', 'UNDO'}
def execute(self, context):
try:
yourfunction(context)
return {'FINISHED'}
except:
self.report({'INFO'}, 'Printing report to Info window.')
return {'CANCELLED'}
-
3$\begingroup$ basically is the already accepted solution of 4 years ago... $\endgroup$– m.arditoNov 10, 2017 at 21:17
-
$\begingroup$ The accepted answer doesn't work without try condition in Blender 2.79 and the return statement and code blocks are clarified here. $\endgroup$ Nov 10, 2017 at 22:54