6

i need to be able to update the dependencies of my drivers via script, does anyone knows how to? thank you very much in advance! my script works on changing the values of the drivers , but sometimes i may need to update

import bpy 
import random # Random floating point number between lo and hi 
def randf(lo, hi): 
    return random.uniform(lo, hi) 
bpy.app.driver_namespace["randf"] = randf
batFINGER
  • 84,216
  • 10
  • 108
  • 233

2 Answers2

4

Here, an awesome guy gave me the solution!

Looking at the source code, the button appears to be a direct function rather than a python operator:

but = uiDefIconTextBut(block, UI_BTYPE_BUT, B_IPO_DEPCHANGE, 
ICON_FILE_REFRESH, IFACE_("Update Dependencies"),
0, 0, 10 * UI_UNIT_X, UI_UNIT_Y,
NULL, 0.0, 0.0, 0, 0,
TIP_("Force updates of dependencies"));
UI_but_func_set(but, driver_update_flags_cb, fcu, NULL);

The way I update a driver in my add-on is by adding and removing a space on the driver’s expression attribute. As far as I could tell, it acts the same way:

driver.expression += " "
driver.expression = driver.expression[:-1]
gandalf3
  • 157,169
  • 58
  • 601
  • 1,133
4

When I had the same issue during driving a node group node (mixShader), I solved it by finding the expression in bpy.data and just setting it to the original expression. More or less a same hack as Francesco Shanigawe Kobane, but saves one line.

bpy.data.node_groups["<NodeGroup>"].animation_data.drivers[0].driver.expression = '<expression>'

Aventau
  • 51
  • 5