6
$\begingroup$

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
$\endgroup$
5
  • $\begingroup$ could you provide a script mwe? $\endgroup$ Sep 14, 2018 at 12:04
  • $\begingroup$ 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 $\endgroup$ Sep 14, 2018 at 12:20
  • $\begingroup$ @miceterminator $\endgroup$ Sep 14, 2018 at 12:21
  • $\begingroup$ Can you clarify "driver dependencies" Is what is referred to as the_"update"_ effectively the result of re-running script above, ie setting ranf to another float between 0 and 1, How / when to flag the update? $\endgroup$
    – batFINGER
    Sep 14, 2018 at 14:51
  • $\begingroup$ @batFINGER you know the button "update dependencies" in the driver panel in the graph editor? i wanted to access that one. by the way , somebody already gave me a solution : blenderartists.org/t/driver-update-dependencies-via-script/… $\endgroup$ Sep 14, 2018 at 17:56

2 Answers 2

3
$\begingroup$

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]
$\endgroup$
3
$\begingroup$

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>'

$\endgroup$
1
  • $\begingroup$ thank you so much @aventau for the answer! gonna try that! $\endgroup$ Dec 6, 2019 at 10:21

You must log in to answer this question.

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