1
$\begingroup$

I want to add a driver to multiple objects within a collection using an empty as target object. This is how far I came Screenshot. I am facing two problems: 1. the script only adds a driver to the active object, not to ALL of the objects. 2. The Python ToolTips tell me that linking the empty as target object should be something with DriverTarget.id but I cannot figure out where to put this within my code.

$\endgroup$

1 Answer 1

2
$\begingroup$
import bpy

empty = bpy.data.objects["Empty"]

for obj in bpy.data.collections["Collection"].all_objects:
    if obj.type == "MESH":
        fcs = obj.driver_add("delta_location", -1)
        for i, fc in enumerate(fcs):
            dr = fc.driver
            v = fc.driver.variables.new()
            tar0 = v.targets[0]
            tar0.id = empty
            tar0.data_path = f"location[{i}]"
            dr.expression = v.name
$\endgroup$

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.