Text(ID)

base classes — bpy_struct, ID

class bpy.types.Text(ID)

Text data-block referencing an external or packed text file

current_character

Index of current character in current line, and also start index of character in selection if one exists (in [0, inf], default 0)

Type:

int

current_line

Current line, and start line of selection if one exists (readonly, never None)

Type:

TextLine

current_line_index

Index of current TextLine in TextLine collection (in [-inf, inf], default 0)

Type:

int

filepath

Filename of the text file (default “”, never None)

Type:

str

indentation

Use tabs or spaces for indentation (default 'TABS')

  • TABS Tabs – Indent using tabs.

  • SPACES Spaces – Indent using spaces.

Type:

Literal[‘TABS’, ‘SPACES’]

is_dirty

Text file has been edited since last save (default False, readonly)

Type:

bool

is_in_memory

Text file is in memory, without a corresponding file on disk (default False, readonly)

Type:

bool

is_modified

Text file on disk is different than the one in memory (default False, readonly)

Type:

bool

lines

Lines of text (default None, readonly)

Type:

bpy_prop_collection[TextLine]

select_end_character

Index of character after end of selection in the selection end line (in [0, inf], default 0)

Type:

int

select_end_line

End line of selection (readonly, never None)

Type:

TextLine

select_end_line_index

Index of last TextLine in selection (in [-inf, inf], default 0)

Type:

int

use_module

Run this text as a Python script on loading (default False)

Type:

bool

users_logic

Logic bricks that use this text

(readonly)

clear()

clear the text block

write(text)

write text at the cursor location and advance to the end of the text block

Parameters:

text (str) – New text for this data-block (never None)

from_string(text)

Replace text with this string.

Parameters:

text (str) – (never None)

as_string()

Return the text as a string

Returns:

(never None)

Return type:

str

is_syntax_highlight_supported()

Returns True if the editor supports syntax highlighting for the current text data-block

Return type:

bool

select_set(line_start, char_start, line_end, char_end)

Set selection range by line and character index

Parameters:
  • line_start (int) – Start Line, (in [-inf, inf])

  • char_start (int) – Start Character, (in [-inf, inf])

  • line_end (int) – End Line, (in [-inf, inf])

  • char_end (int) – End Character, (in [-inf, inf])

cursor_set(line, *, character=0, select=False)

Set cursor by line and (optionally) character index

Parameters:
  • line (int) – Line, (in [0, inf])

  • character (int) – Character, (in [0, inf], optional)

  • select (bool) – Select when moving the cursor (optional)

as_module()
classmethod bl_rna_get_subclass(id, default=None, /)
Parameters:
  • id (str) – The RNA type identifier.

  • default (bpy.types.Struct | None) – The value to return when not found.

Returns:

The RNA type or default when not found.

Return type:

bpy.types.Struct

classmethod bl_rna_get_subclass_py(id, default=None, /)
Parameters:
  • id (str) – The RNA type identifier.

  • default (type | None) – The value to return when not found.

Returns:

The class or default when not found.

Return type:

type

region_as_string(*, range=None)
Parameters:

range (tuple[tuple[int, int], tuple[int, int]] | None) – The region of text to be returned, defaulting to the selection when no range is passed. Each int pair represents a line and column: ((start_line, start_column), (end_line, end_column)) The values match Python’s slicing logic (negative values count backwards from the end, the end value is not inclusive).

Returns:

The specified region as a string.

Return type:

str

region_from_string(body, /, *, range=None)
Parameters:
  • body (str) – The text to be inserted.

  • range (tuple[tuple[int, int], tuple[int, int]] | None) – The region of text to be returned, defaulting to the selection when no range is passed. Each int pair represents a line and column: ((start_line, start_column), (end_line, end_column)) The values match Python’s slicing logic (negative values count backwards from the end, the end value is not inclusive).

Inherited Properties

Inherited Functions

References