0
$\begingroup$

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

text3d

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.

$\endgroup$
1
$\begingroup$

enter image description here

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)

enter image description here

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')
$\endgroup$
1
  • $\begingroup$ select_set() is not a part of Blender2.79 api $\endgroup$
    – starzar
    May 4 '20 at 11:28

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.