2
$\begingroup$

I was wondering how to find which text file is open in the text editor. I know you can find a list of the loaded files via bpy.data.texts, but I can't seem to find a way to find the one that is being edited currently.

$\endgroup$
1

1 Answer 1

3
$\begingroup$

Active text datablocks are referenced by TextEditor spaces:

bpy.types.SpaceTextEditor.text

for area in bpy.context.screen.areas:
    if area.type == 'TEXT_EDITOR':
        space = area.spaces.active
        print(repr(space.text))

# Example output with one visible text editor:
# bpy.data.texts['ui_menu_simple.py']
$\endgroup$
1

You must log in to answer this question.

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