Counting amount of lines in a text object
TextCurve.body



Split the text curve body by a newline. Count the result.

&gt;&gt;&gt; D.objects['Text'].data
bpy.data.curves['Text']

&gt;&gt;&gt; D.curves['Text'].body

'Line 1\nLine 2'

&gt;&gt;&gt; len(D.curves['Text'].body.split("\n"))
2


for overflowing text,



one method to guestimate this would be to set overflowing textbox X size to desired width and Y size to 0. A copy of the object with only one character will have the height of one line.

import bpy
context = bpy.context

text = context.object
copy = text.copy()
font = copy.data = text.data.copy()
font.body = "0"
context.collection.objects.link(copy)
context.scene.update()
print(round(text.dimensions.y / copy.dimensions.y))
bpy.data.objects.remove(copy)


If there is line spacing then two lines will be 2 x line height + line space.  I vaguely recall a more accurate way to calculate font dimension, but have not fount the link.

Related Any idea how to fit text width to screen

Text.lines



Python console code.

&gt;&gt;&gt; D.texts['Text']
bpy.data.texts['Text']

&gt;&gt;&gt; len(D.texts['Text'].lines)
2

&gt;&gt;&gt; for line in D.texts['Text'].lines:
...     line.body
...     
'line 1'
'line 2'