15
$\begingroup$

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.

$\endgroup$
19
$\begingroup$

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.

$\endgroup$
  • 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 get Undefined Type: Printing report to Info window. {'FINISHED'} and there is no printing to the report window.. $\endgroup$ – zeffii Jun 8 '13 at 11:33
  • 1
    $\begingroup$ 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) $\endgroup$ – Adhi Jun 8 '13 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$ – brecht Jun 8 '13 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 operator bpy.ops.render.oha1_test() $\endgroup$ – user918 Jul 9 '13 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$ – Adhi Jul 9 '13 at 5:16
3
$\begingroup$

I needed to display a notification message when running a script in the Text Editor by hitting the 'Run Script' button.

None of the above methods worked for this purpose :/

But this worked, even though it's not the preferred way :)

That is:

import bpy

def oops(self, context):
    self.layout.label("You have done something you shouldn't do!")

bpy.context.window_manager.popup_menu(oops, title="Error", icon='ERROR')

enter image description here

$\endgroup$
-2
$\begingroup$

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'}
$\endgroup$
  • 3
    $\begingroup$ basically is the already accepted solution of 4 years ago... $\endgroup$ – m.ardito Nov 10 '17 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$ – Fahad Hasan Pathik Nov 10 '17 at 22:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.