6
$\begingroup$

Cannot find proper bpy.ops command to switch texts in Text Editor(normally you do that from area header by clicking and selecting text block).

bpy.context.space_data.text is read only.

Is there a way?

Edit: the property is writable, my mistake, everything is fine.

$\endgroup$

1 Answer 1

8
$\begingroup$

You can change it via bpy.types.SpaceTextEditor.text

So if you run an operator from the text editor you can change it in the execute method like this:

def execute(self, context):
    context.space_data.text = bpy.data.texts['your_text']

Otherwise you have to find the text area in screen.areas (given there is a text editor in the screen):

for area in context.screen.areas:
    if area.type == "TEXT_EDITOR":
        break
    else:
        raise RuntimeError("Nothing found")

area.spaces[0].text = bpy.data.texts['your_text']
$\endgroup$
1
  • $\begingroup$ My statement that bpy.context.space_data.text is read-only is false, thanks. It was greyed out in outliner datablocks and that confused me, it makes sense its greyed out. $\endgroup$ Commented Dec 3, 2014 at 16:46

You must log in to answer this question.

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