I am trying to write informations of what my script is doing in the textblock. I have the Python script to call it but I don't know how to put text in it:


What is the code to write "Hello world!" inside?


1 Answer 1


An example using simple operator template, the 'REGISTER' option in bl_options set which among other things makes sure "bpy.ops.object.simple_operator" makes its way into the report created by bpy.ops.ui.reports_to_textblock().

A call to self.report(type, message) writes to the report area, when run from UI. For an Operator report The type can be set of one of ('DEBUG', 'INFO', 'OPERATOR', 'PROPERTY', 'WARNING', 'ERROR', 'ERROR_INVALID_INPUT', 'ERROR_INVALID_CONTEXT', 'ERROR_OUT_OF_MEMORY')

class SimpleOperator(bpy.types.Operator):
    bl_idname = "object.simple_operator"
    bl_label = "Simple Object Operator"
    bl_options = {'REGISTER'}

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

    def execute(self, context):
        self.report({'INFO'}, "Hello World")
        return {'FINISHED'}

After running the simple operator, then ui.reports_to_textblock(), the "Recent Reports" textblock will contain,

Operator: bpy.ops.object.simple_operator()
Info: Hello World

In case you want to to open a textblock to write reports to, use API methods, textblock below is of type Text

import bpy

textblock = bpy.data.texts.get("RM_Report")

if not textblock:
    textblock = bpy.data.texts.new("RM_Report")

textblock.write("Hello World\n")
  • $\begingroup$ Thank you for the answer. I have copy/pasted your code but the textblock doesnt shows up near the render engine selection. $\endgroup$ Jun 15, 2016 at 15:18

You must log in to answer this question.

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