1
$\begingroup$

What is the best way to inform users of an add-on's warnings, info, or things they must do for the function to work? As it seems to be hard to add info to the main header, is it better to use (Blender dreaded) pop-ups? So what are your preferred ways and how do you do it, code-wise?

(I don't mean info view or console, because users do not have these things open - so this is not a duplicate question)

$\endgroup$
0

2 Answers 2

5
$\begingroup$

Prefered way is to use Operator.report() method. You only need to pass a certain type of report 'INFO', 'ERROR', 'WARNING' etc. and the corresponding message as string. In case of an error report a popup appears as well as the message is shown in the info bar, automatically.

enter image description here

import bpy
import random

class SimpleOperator(bpy.types.Operator):
    """Tooltip"""
    bl_idname = "object.simple_operator"
    bl_label = "Simple Object Operator"

    @classmethod
    def poll(cls, context):
        return context.active_object is not None

    def execute(self, context):
        if bool(random.getrandbits(1)):
            self.report({'ERROR'}, 'Error message')
        else:
            self.report({'INFO'}, 'Info message')
        return {'FINISHED'}

def register():
    bpy.utils.register_class(SimpleOperator)

def unregister():
    bpy.utils.unregister_class(SimpleOperator)


if __name__ == "__main__":
    register()

Example based on Python > Templates > Operator Simple.

$\endgroup$
1
  • $\begingroup$ Any idea how to dynamically change the error / info message (from within python)? I was considering to use such an operator as logging class (that logs the output to the info area). But looking at the example above, it guess there is no obvious approach to change that? $\endgroup$ Commented Oct 22, 2020 at 8:48
3
$\begingroup$

https://docs.blender.org/api/current/bpy.types.WindowManager.html#bpy.types.WindowManager.popup_menu

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

do

$\endgroup$
2
  • 4
    $\begingroup$ Prefered way is to use Operator.report() method, check out the API: docs.blender.org/api/current/… $\endgroup$
    – brockmann
    Commented Dec 17, 2017 at 14:14
  • 5
    $\begingroup$ This blocks the user interface, which is against Blender's UI paradigm. Use Operator.report() instead. $\endgroup$
    – dr. Sybren
    Commented Dec 18, 2017 at 13:16

Not the answer you're looking for? Browse other questions tagged .