0
$\begingroup$

I can add a text field to blender go to edit mode and add more text and hit return at the end of each line to get more lines and go back to object mode and object is a single object.

How can I use a python script to do the same. in other words I like the following on the screen

Line1 some text

Line2 more text

Line3 more text

.etc

all as one text object.

$\endgroup$

1 Answer 1

1
$\begingroup$
import bpy
bpy.ops.object.text_add()
ob = bpy.context.object
ob.data.body = """Line1 some text
Line2 more text
Line3 more text"""

""" in Python denotes a multiline string. You can also Just use the newline character \n:

ob.data.body = "Line1 some text\nLine2 more text\nLine3 more text"

as well as many other techniques: Pythonic way to create a long multi-line string

$\endgroup$
2
  • $\begingroup$ how would if be formated if each line is an array element ob.data.body = """ field[0] + field[1] + field[2]""" ? $\endgroup$ Feb 8, 2021 at 1:51
  • $\begingroup$ @MattieVoohies try '\n'.join(field). If those elements are not strings, you will have to convert them to strings: ob.data.body = '\n'.join(map(str, field)) $\endgroup$ Feb 8, 2021 at 10:04

You must log in to answer this question.

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