Take the 2-minute tour ×
Blender Stack Exchange is a question and answer site for people who use Blender to create 3D graphics, animations, or games. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 1

up vote 2 down vote accepted

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)>
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.