# Python Text to 3dObject

The TextEditor comes with a feature to covert selected text in the editor to 3d_object.
TextEditor->Edit->Text to3d_object.

It's unfortunate that the api doesn't provide a way to directly input text as a string into the Operator

bpy.ops.text.to_3d_object(split_lines=False)


Since " manually selected text " from a text file is the only way to provide input to this operator,is there any way to get access to this selected text within a Python/Text file , before executing this operator so that it get's directly converted to 3d_object.

To get the selection, remember the lines are displayed from 1, but counted from 0 in the text buffer.

>>> t = D.texts['Text.002']
>>> t.current_character
10

>>> t.current_line_index
12

>>> t.select_end_character
4

>>> t.select_end_line_index
16


To set the selection

>>> t.select_set(
select_set()
Text.select_set(line_start, char_start, line_end, char_end)
Set selection range by line and character index

>>> t.select_set(0, 0, 4, 22)


Text file buffer.

>>> for i, l in enumerate(t.lines):
...     i, l.body
...
(0, 'import bpy')
(1, 'import bmesh')
(2, 'context = bpy.context')
(3, '')
(4, 'context.tool_settings.mesh_select_mode = (False, False, True) # faces')
(5, 'ob = context.edit_object')
(6, 'me = ob.data')

• select_set() is not a part of Blender2.79 api – starzar May 4 '20 at 11:28