I am trying to measure a Text Object with Python, but I am getting discrepancies when I run my code in the Blender Python Console and then in the Text Editor (with output to the System Console).

My code is as follows:

import bpy

# Create text object
obj = bpy.ops.object.text_add(location=(0,0,0))

# Set the text
bpy.context.active_object.data.body = "Hello World!"

# Find the text size (try with two methods)
dimensions1 = bpy.context.active_object.dimensions

dimensions2 = bpy.context.object.dimensions

If I run this code from the Blender Console I get the following object in the viewport (measured to be like 5.3 m in the x direction, with the Measure tool, as shown):

SCript result

And the Blender Console reports the correct size as a result (5.3160 in the x direction):

<Vector (5.3160, 0.7000, 0.0000)>
<Vector (5.3160, 0.7000, 0.0000)>

But if I run the very same code from the Text Editor, which reports the results to the system console the size reported in the System Console is quite different:

<Vector (1.8980, 0.6910, 0.0000)>
<Vector (1.8980, 0.6910, 0.0000)>

Yet the object in the viewport is keeps the same size as the first one (5.3 m)!?

  • Am I doing something wrong?
  • Why one method gives the correct result (5.3 m) and the other not (1.89 m)?
  • Why the mismatch between the results?
  • Can you reproduce these results on your computers?

Thanks in advance for your ideas.

(I am using Blender 2.83.0 on Mac OS 10.13.6).

  • $\begingroup$ Should work on text objects as well: blender.stackexchange.com/a/8470/31447 $\endgroup$
    – brockmann
    Jul 19, 2020 at 4:16
  • $\begingroup$ Thanks, @brockmann. I just tried the method you refers. Sadly it does not fix the problem. I keep getting different results from the System Terminal and the Blender Console. Is this a bug in Blender? $\endgroup$ Jul 19, 2020 at 20:17


You must log in to answer this question.

Browse other questions tagged .