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
print(dimensions1)
dimensions2 = bpy.context.object.dimensions
print(dimensions2)
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):
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).
