4
$\begingroup$

quick version:see the image

In short, I'm looking for correct way to use "driver_add("path", index)" to add driver to geometry node input.

Creating drivers in common modifiers are easy:

For example creating a driver at the width paramater of bevel modifier using the script below.

# Get the object and modifier
cube = bpy.data.objects["Cube"]
bevel_mod = cube.modifiers["Bevel"]

# Create a new driver for the Bevel modifier width parameter
driver = bevel_mod.driver_add("width").driver

However when facing geometry nodes, it does not work.

Because there is "[" after the modifier, rather than ".":

GeometryNode Input path: bpy.data.objects["Cube"].modifiers["GeometryNodes"]["Input_2"]

Bevel Input path: bpy.data.objects["Cube"].modifiers["Bevel"].width

I can add driver manually to both modifiers by right click, but I have 88 objects to add driver to.

enter image description here

$\endgroup$

1 Answer 1

4
$\begingroup$

Add driver to GeometryNodes input

import bpy

md = bpy.context.object.modifiers["GeometryNodes"]

fc = md.driver_add('["Input_2"]')

# need update the interface manually (place the cursor on the input box)
$\endgroup$
1
  • $\begingroup$ wow, so simple! Perfectly solved my confusion! $\endgroup$
    – Azona77
    Commented Jul 6, 2023 at 8:24

You must log in to answer this question.

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