6
$\begingroup$

I have a button created by my script. I wonder how I can display what the system console displays but inside blender's console. CoDEmanX did this by running a script inside it as shown here, but I want to display what happens in the system console inside blender's console.

My .blend file can be found here:

$\endgroup$
  • $\begingroup$ but inside blender - is too vauge, where exactly? $\endgroup$ – ideasman42 Apr 23 '17 at 9:10
  • $\begingroup$ @ideasman42 question updated as suggested. $\endgroup$ – Tak Apr 23 '17 at 10:24
8
$\begingroup$

Hello world example that prints text into the first console found.

import bpy

def console_get():
    for area in bpy.context.screen.areas:
        if area.type == 'CONSOLE':
            for space in area.spaces:
                if space.type == 'CONSOLE':
                    return area, space
    return None, None


def console_write(text):
    area, space = console_get()
    if space is None:
        return

    context = bpy.context.copy()
    context.update(dict(
        space=space,
        area=area,
    ))
    for line in text.split("\n"):
        bpy.ops.console.scrollback_append(context, text=line, type='OUTPUT')

console_write("Hello World")
$\endgroup$

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.