2
$\begingroup$

When using Python to add a driver to a vector, i.e. the constant offset of an array modifier, it adds drivers to all three components while I only need to drive one of them.

Is there a way to add a driver to only one component, or perhaps to add drivers to all three and then delete the unnecessary two?

Here's how I add the driver:

arr_mod = active_object.modifiers.new("Array", 'ARRAY')
fcurves = arr_mod.driver_add('constant_offset_displace')
$\endgroup$
2
  • $\begingroup$ Post a minified code snippet showing your problem - the fix is simple you need to define which channel to drive… $\endgroup$ Commented Oct 2, 2023 at 13:19
  • $\begingroup$ Thanks Markus. I've updated my question with a code snippet. $\endgroup$
    – gcs_dev
    Commented Oct 2, 2023 at 13:41

1 Answer 1

2
$\begingroup$

Here's an updated snippet that adds a driver only to the $y$ component of the constant offset:

from bpy import context as C

arr_mod = C.object.modifiers.new("Array", 'ARRAY')
arr_mod.use_constant_offset = True
fcurves = arr_mod.driver_add('constant_offset_displace', 1)

Probably needless to say, the $xyz$ components have $0, 1, 2$ indices in that order.

When writing the code in the Python Console, you can hit ⭾ Tab after opening parenthesis of driver_add( to see hints on how to use it:

$\endgroup$
1
  • 1
    $\begingroup$ Wow! So simple. Thanks a lot Markus, that's a great answer! $\endgroup$
    – gcs_dev
    Commented Oct 2, 2023 at 14:58

You must log in to answer this question.

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