# How do I use python to get the dimensions of a text object immediately after it is created?

I'm creating a text object using Python and I'd like to do a non-standard align (something other than left/right/center). To accomplish this I need the dimensions, but the dimensions.x is 0 at the time the python is running. It becomes non-zero later

import bpy

name = "text1"

t1 = bpy.data.curves.new(name, 'FONT')
o1 = bpy.data.objects.new(name, t1)
o1.location = (0,0,2)

t1.body = "Hail Bob!"

c1 = o1.constraints.new('TRACK_TO')
c1.target = bpy.data.objects["Camera"]
c1.track_axis = 'TRACK_Z'
c1.up_axis = 'UP_Y'

if False:
t1.align = 'RIGHT'
else:
print (o1.dimensions.x)
t1.text_boxes[0].x = o1.dimensions.x * -0.3


Is there a blender API that will trigger a calculation of the dimensions property of the object so that I can use it before returning control to the UI?

Since there's no .update() method for Curve objects, you need to trigger a scene update:
t1.body = "Hail Bob!"

<Vector (3.6080, 0.7000, 0.0000)>

• For 2.80: bpy.context.view_layer.update() Dec 8 '19 at 12:00