4

I copied full datapath for my property Vertices X as shown below and set it via python using bpy.data.objects["Cube"].modifiers["GeometryNodes"]["Socket_2"] = 5. The value will update when you hover over it but it does not update the 3D View evidenced in the GN tree socket value it's still 2 instead of 5. Why? I found this thread but no answer. Is this a bug?

I also tried context.view_layer.update() but that didn't help...

enter image description here

I noticed that when I manually toggle back and forth it works but if I do it with script it doesn't:

bpy.data.objects["Cube"].modifiers["GeometryNodes"]["Socket_2"] = 5
bpy.ops.object.mode_set_toggle()
bpy.ops.object.mode_set_toggle()

I also found this answer and tried this:

dg = bpy.context.evaluated_depsgraph_get()
dg.update() 

But that also doesn't work. Is this maybe a bug I should log?

Megan Love
  • 360
  • 12

1 Answers1

5

You can do the following:

import bpy

cube = bpy.data.objects["Cube"]

cube.modifiers["GeometryNodes"]["Socket_2"] = 2

cube.modifiers.update()

cube.update_tag()

About cube.modifiers.update() the Python console says

update() .. method:: update() Execute the properties update callback. .. note:: This is called when assigning a property, however in rare cases it's useful to call explicitly.

lemon
  • 60,295
  • 3
  • 66
  • 136