1
$\begingroup$

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.

$\endgroup$

1 Answer 1

2
$\begingroup$

The solution is to call bpy.context.view_layer.update() after loading a new font in to the text object.

$\endgroup$
3
  • 2
    $\begingroup$ Perhaps text.evaluated_get(...).dimensions is worth considering too. $\endgroup$
    – batFINGER
    Jul 10, 2020 at 19:11
  • $\begingroup$ Would you please link me to docs where I can learn how this works ? $\endgroup$
    – Auchan
    Jul 13, 2020 at 13:51
  • $\begingroup$ I assume this is by getting the dependency graph of an object and update it with new values so it gets updated ? Thanks $\endgroup$
    – Auchan
    Jul 13, 2020 at 14:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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