21

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.

zeffii
  • 39,634
  • 9
  • 103
  • 186

3 Answers3

27

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:

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.

p2or
  • 15,860
  • 10
  • 83
  • 143
Adhi
  • 14,310
  • 1
  • 55
  • 62
  • 2
    i made this snippet to demo a problem i've experienced: https://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 get `Undefined Type: Printing report to Info window.

    {'FINISHED'}` and there is no printing to the report window..

    – zeffii Jun 08 '13 at 11:33
  • 1
    When the enumeration type is only INFO, WARNING or ERROR, the message is prefixed accordingly (e.g. "Info: ..."). But if we add DEBUG, 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. (and report doesn't output to report area if executed on a Python interpreter area) – Adhi Jun 08 '13 at 11:57
  • I don't think multiple values were intended to work, just use one value. They are more like importance levels where DEBUG is the lowest and ERROR is the highest. – brecht Jun 08 '13 at 12:01
  • @brecht I don't know how it's supposed to be used, as there's no documentation. Just trying combination and it just works. And only specifying DEBUG outputs nothing, either in shell, Info's report area or header. – Adhi Jun 08 '13 at 12:07
  • 3
    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. – brecht Jun 08 '13 at 12:19
  • Oh, the code in blenkernel/intern/report.c uses switch instead of bitwise ops. That explains... – Adhi Jun 08 '13 at 12:23
  • OK, thanks guys. The takeaway here is once the script is running it is reasonably easy to send messages to the info window. example: https://gist.github.com/zeffii/5735019 – zeffii Jun 08 '13 at 12:31
  • @brecht Ah yes, it does nothing. Combining DEBUG and other type suppresses output to Info area's header, though, which led me to think it has some use :) I concede that it's probably unintended. – Adhi Jun 08 '13 at 16:59
  • 2
    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 operator

    bpy.ops.render.oha1_test()

    – user918 Jul 09 '13 at 04:13
  • 2
    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. – Adhi Jul 09 '13 at 05:16
11

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')

enter image description here

brockmann
  • 12,613
  • 4
  • 50
  • 93
Manu Järvinen
  • 7,392
  • 2
  • 25
  • 62
  • with newer version of blender 2.9x use self.layout.label(text="You have done something you shouldn't do!") – cscholl Feb 15 '21 at 10:48
-3

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'}