Text(ID)

base classes — bpy_struct, ID

class bpy.types.Text.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

Type

int in [0, inf], default 0

current_line

Current line, and start line of selection if one exists

Type

TextLine, (readonly, never None)

current_line_index

Index of current TextLine in TextLine collection

Type

int in [-inf, inf], default 0

filepath

Filename of the text file

Type

string, default “”, (never None)

indentation

Use tabs or spaces for indentation

  • TABS Tabs, Indent using tabs.

  • SPACES Spaces, Indent using spaces.

Type

enum in [‘TABS’, ‘SPACES’], default ‘TABS’

is_dirty

Text file has been edited since last save

Type

boolean, default False, (readonly)

is_in_memory

Text file is in memory, without a corresponding file on disk

Type

boolean, default False, (readonly)

is_modified

Text file on disk is different than the one in memory

Type

boolean, default False, (readonly)

lines

Lines of text

Type

bpy_prop_collection of TextLine, (readonly)

select_end_character

Index of character after end of selection in the selection end line

Type

int in [0, inf], default 0

select_end_line

End line of selection

Type

TextLine, (readonly, never None)

select_end_line_index

Index of last TextLine in selection

Type

int in [-inf, inf], default 0

use_module

Run this text as a script on loading, Text name must end with “.py”

Type

boolean, default False

clear()

clear the text block

write(text)

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

Parameters

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

is_syntax_highlight_supported()

Returns True if the editor supports syntax highlighting for the current text datablock

Return type

boolean

select_set(line_start, char_start, line_end, char_end)

Set selection range by line and character index

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

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

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

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

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

Set cursor by line and (optionally) character index

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

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

  • select (boolean, (optional)) – Select when moving the cursor

as_module()
as_string()

Return the text as a string.

from_string(string)

Replace text with this string.

classmethod bl_rna_get_subclass(id, default=None)
Parameters

id (string) – The RNA type identifier.

Returns

The RNA type or default when not found.

Return type

bpy.types.Struct subclass

classmethod bl_rna_get_subclass_py(id, default=None)
Parameters

id (string) – The RNA type identifier.

Returns

The class or default when not found.

Return type

type

Inherited Properties

  • bpy_struct.id_data

  • ID.name

  • ID.name_full

  • ID.is_evaluated

  • ID.original

  • ID.users

  • ID.use_fake_user

  • ID.is_embedded_data

  • ID.tag

  • ID.is_library_indirect

  • ID.library

  • ID.override_library

  • ID.preview

Inherited Functions

  • bpy_struct.as_pointer

  • bpy_struct.driver_add

  • bpy_struct.driver_remove

  • bpy_struct.get

  • bpy_struct.is_property_hidden

  • bpy_struct.is_property_overridable_library

  • bpy_struct.is_property_readonly

  • bpy_struct.is_property_set

  • bpy_struct.items

  • bpy_struct.keyframe_delete

  • bpy_struct.keyframe_insert

  • bpy_struct.keys

  • bpy_struct.path_from_id

  • bpy_struct.path_resolve

  • bpy_struct.pop

  • bpy_struct.property_overridable_library_set

  • bpy_struct.property_unset

  • bpy_struct.type_recast

  • bpy_struct.values

  • ID.evaluated_get

  • ID.copy

  • ID.override_create

  • ID.user_clear

  • ID.user_remap

  • ID.make_local

  • ID.user_of_id

  • ID.animation_data_create

  • ID.animation_data_clear

  • ID.update_tag

  • ID.bl_rna_get_subclass

  • ID.bl_rna_get_subclass_py

References

  • bpy.context.edit_text

  • BlendData.texts

  • BlendDataTexts.load

  • BlendDataTexts.new

  • BlendDataTexts.remove

  • FreestyleModuleSettings.script

  • NodeFrame.text

  • PythonConstraint.text

  • ShaderNodeScript.script

  • ShaderNodeTexIES.ies

  • SpaceTextEditor.text