6
$\begingroup$

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)
bpy.context.scene.objects.link(o1)

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?

$\endgroup$

1 Answer 1

5
$\begingroup$

Since there's no .update() method for Curve objects, you need to trigger a scene update:

t1.body = "Hail Bob!"
bpy.context.scene.update()
print(o1.dimensions)

Result:

<Vector (3.6080, 0.7000, 0.0000)>
$\endgroup$
1
  • 1
    $\begingroup$ For 2.80: bpy.context.view_layer.update() $\endgroup$ Commented Dec 8, 2019 at 12:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .