4
$\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$
5
$\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$
  • $\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$ – Jaroslav Jerryno Novotny Dec 3 '14 at 16:46

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.