# Discrepancy in text object sizes?

I'm writing a Python script that is pretty sensitive to the x-size ("length") of text objects created with the function text_add(). (I'm also new to Blender and still very confused about where the standard output from the Text Editor goes; some people mention it should go to "the console", but it definitely doesn't go to my Python Console inside Blender - and I'm using version 2.79 - so the following code sample reflects this confusion).

Problem: a text object displaying 30 Is (capital I) is not six times longer than a similar text object displaying 5 Is - it's much longer. I'm running the script from the Text Editor, but it shows the same results from the Python Console. Since I don't know how to show these values in some Blender window (see above) I had to rig the example so it shows them in other text objects. The two text objects (the "short" and the "long" one) are renamed to T1/T2 after creation. Two "control" text objects (T1_Ctl/T2_Ctl) display the x-size ("length") of T1/T2. The following code could be run after loading the default blend file, deleting the cube, and opening a Text Editor window.

import bpy
# Set the scene units to millimeters and set the grid to a reasonable size
bpy.context.scene.unit_settings.system = 'METRIC'
bpy.context.scene.unit_settings.scale_length = 0.001
for area in bpy.context.screen.areas:
if (area.type == 'VIEW_3D'):
area.spaces.active.grid_scale = 0.01

# Add a "short" text object
obj = bpy.data.objects['Text']
obj.name = 'T1'
obj.data.body = 'IIIII'  # 5 Is
# Add a "long" text object (presumably 6 times longer)
obj = bpy.data.objects['Text']
obj.name = 'T2'
obj.data.body = 'IIIIIIIIIIIIIIIIIIIIIIIIIIIIII'  # 30 Is
# Control text object - shows the length of the "short" text object
obj = bpy.data.objects['Text']
obj.name = 'T1_Ctl'
obj.data.body = str(bpy.data.objects['T1'].dimensions.x)
# Control text object - shows the length of the "long" text object
obj = bpy.data.objects['Text']
obj.name = 'T2_Ctl'
obj.data.body = str(bpy.data.objects['T2'].dimensions.x)


After running the script, the length of the short text object is reported as 7.686, while the length of the long text object shows as 51.436 (6.7 times longer), which means the longer text is almost 7 times, not 6 times longer.

Does anybody know what's happening here? Where is this extra "padding" coming from? How can I get an accurate length of a text object?

• Suggest using obj = context.object to reference an object after an operator that creates a new object and sets it to context. Do you get same result when font fixed width and proportional? – batFINGER Dec 12 '17 at 14:55
• I think I know what's happening. In the long string there are indeed 6 groups of 5 Is, so my assumption was that the length of the long string should be 6 times the length of the short one. But the long string also contains 5 extra inter-character spaces. I think that if I set the inter-character spacing to zero, the length of the long string will become exactly 6 times the length of the short one, which would be re-assuring, because it would prove that there is no discrepancy (just false expectations on my side). I'll try to do this tomorrow and I'll post the code changes here if it works. – Dan Dec 12 '17 at 23:10
• Open up the console first, that is where your text editor output goes. – Leander May 28 '18 at 6:38