# How to use the textblock operator in Python

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:

bpy.ops.ui.reports_to_textblock()

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

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):
"""Tooltip"""
bl_idname = "object.simple_operator"
bl_label = "Simple Object Operator"
bl_options = {'REGISTER'}

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

def execute(self, context):
self.report({'INFO'}, "Hello World")
main(context)
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")

• Thank you for the answer. I have copy/pasted your code but the textblock doesnt shows up near the render engine selection. – Danyl Bekhoucha Jun 15 '16 at 15:18