# Dimensions won't get updated via bpy script

So I have two text objects that I am changing via a Python script, but dimensions of said text objects won't update. The file is saved with said text objects with a base X dimension of 0.6

But when print the objects dimension while running the script, I got different dimensions, like 0.4 or 0.7. This results on the text boxes changing in side and ignoring the assignment in the script OR the base values on the scene file, which is 0.6 on both cases.

Example :

text = bpy.data.objects['text_superior']
text.dimensions = (0.6,0.5,0.0)


And:

https://docs.blender.org/api/current/bpy.types.Object.html#bpy.types.Object.dimensions

dimensions

Absolute bounding box dimensions of the object (WARNING: assigning to it or its members multiple consecutive times will not work correctly, as this needs up-to-date evaluated data)

Does this mean I need to somehow do some kind of object or scene update after assigning the new dimensions to the text object in the script ?

EDIT: I just realized that it's when I load a new font like:

text.data.font = bpy.data.fonts.load('font.ttf')


The dimension of the box changes. This might make sense, but then I assign new dimensions with

text.dimensions = (0.6,0.5,0.0)


And it's when it doesn't update.

The solution is to call bpy.context.view_layer.update() after loading a new font in to the text object.
• Perhaps text.evaluated_get(...).dimensions is worth considering too. Jul 10 '20 at 19:11