1
$\begingroup$

I have created an object using geometry nodes. I control its input node "String." I want to control the position of this object based on the x dimension, but when I change the string (therefore, the dimensions of the object), it does not update immediately. Instead, it keeps the location of the previous string, and only when I rerun the script again, the object moves to the correct position.

import bpy

Texts = bpy.data.collections["Texts"].objects

bpy.data.node_groups["Geometry Nodes"].nodes["String"].string = 'The Text I Want To Change'

Texts[0].location[0] = 0 - Texts[0].dimensions.x/2 

My Geometry nodes

gif

$\endgroup$
4
  • $\begingroup$ This works immediately for me. What Blender version are you using? I'm on 3.3.0 $\endgroup$
    – Psyonic
    Commented Nov 26, 2022 at 22:55
  • $\begingroup$ I use 3.3.1, so it should not be a problem. Have you also tried to change the string after the first use? I edited the question, so my problem is more clear. $\endgroup$ Commented Nov 28, 2022 at 8:38
  • 1
    $\begingroup$ try bpy.context.view_layer.update() $\endgroup$ Commented Nov 28, 2022 at 10:52
  • $\begingroup$ I tried it many times, was kinda fun to play with :) Can you share your .blend please. Edit your question with the link it makes blend-exchange.com $\endgroup$
    – Psyonic
    Commented Nov 28, 2022 at 10:54

1 Answer 1

2
$\begingroup$

Thanks to Markus von Broady

bpy.context.view_layer.update()

This did the trick!

$\endgroup$

You must log in to answer this question.

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