1
$\begingroup$

I use this script to add drivers. But after I execute the script, save the file, close blender, and then open the file again, the driver has lost its track. What can I do? Are there any alternatives?

import bpy

# Driver Blur 
blur_node = bpy.context.scene.node_tree.nodes["Group"].node_tree.nodes["Blur"]
Driver = blur_node.driver_add('size_x')
Input_name = "Blur 1 Size"
Driver.driver.type = 'AVERAGE'
dif_fac_driver = Driver.driver
var = dif_fac_driver.variables.new() # create variable to use
var.name = f'default_value'   # set expression to the variable 
# Set target
var.targets[0].id_type = 'NODETREE'
var.targets[0].id = bpy.context.scene.node_tree
var.targets[0].data_path = f'nodes["Group"].inputs["Input"].default_value' 

$\endgroup$
0

1 Answer 1

2
$\begingroup$

You have to use SCENE instead of NODETREE for the id_type

import bpy

# Driver Blur 
blur_node = bpy.context.scene.node_tree.nodes["Group"].node_tree.nodes["Blur"]
Driver = blur_node.driver_add('size_x')
Input_name = "Blur 1 Size"
Driver.driver.type = 'AVERAGE'
dif_fac_driver = Driver.driver
var = dif_fac_driver.variables.new() # create variable to use
var.name = f'default_value'   # set expression to the variable 
# Set target
var.targets[0].id_type = 'SCENE'
var.targets[0].id = bpy.context.scene
var.targets[0].data_path = 'node_tree.nodes["Group"].inputs["Input"].default_value'
$\endgroup$
3
  • $\begingroup$ Thanks a lot for your help! Is there a reason why this is the case, or is this a bug in blender that can be worked around this way? $\endgroup$
    – Andi
    Commented Apr 20, 2023 at 21:01
  • 1
    $\begingroup$ I get the impression that it's a bug. It's also weird that the size_x/y properties don't have input sockets, which doesnt make any sense. $\endgroup$
    – Harry McKenzie
    Commented Apr 20, 2023 at 21:36
  • $\begingroup$ Good to hear that doesn't make sense. Sometimes it's hard to understand how a particular feature was thought of by the developers. Thanks a lot! $\endgroup$
    – Andi
    Commented Apr 21, 2023 at 6:38

You must log in to answer this question.

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