1
$\begingroup$

I have several objects that share the same material.

This material has a mix shader node, whose the FAC parameter should be linked to a custom property of the object having that material assigned.

From what I read, I need drivers here, so I've set up one (see screenshot).

But I need to set an object as input for the driver. I don't want to select each object manually. What I would like is that the driver refers automatically to the current object.

Is it possible, or do you know a better way to achieve this ? Thanks.

enter image description here

$\endgroup$
1
  • $\begingroup$ So this is what I need to put in the Path field, and leave the Prop field empty ? $\endgroup$
    – gordie
    Oct 27, 2016 at 14:06

1 Answer 1

1
$\begingroup$

In blender 2.78 (and maybe earlier) there is now the use_self option when setting up a driver.

enter image description here

And with a test script

import bpy

def x(self):
    print(self)
    print(getattr(self, "location", None))
    return 0.0

bpy.app.driver_namespace["x"] = x

After adding the driver expression x(self) to a driver on a cone mesh and a material's emit it prints the following to the system console

<bpy_struct, Material("Material")>
None
<bpy_struct, Object("Cone")>
<Vector (0.0000, 0.0000, 0.0000)>

and to return custom prop value, or 0 if there is no custom prop of that name.

def x(self):
    prop = self.get("toggleRedWhite", 0.0)
    return prop

PS. the data_path of a custom property is '["toggleRedWhite"]' How can I add drivers for custom properties?

$\endgroup$
3
  • $\begingroup$ I can confirm there was no 'use self' option in Blender 2.77. $\endgroup$
    – gordie
    Oct 31, 2016 at 12:23
  • $\begingroup$ Ok, I got the option on 2.77a. Thanks for your explanations, I'm sure it will work, but for the moment i'm not able to achieve it. Have I to put a script somewhere ? What should I set for the variable name and prop ? imgur.com/WygnQKV $\endgroup$
    – gordie
    Oct 31, 2016 at 12:43
  • $\begingroup$ @batfinger your self.get("property") line didn't work for me, the driver expression is valid but when I move the custom property value it does not drive the driver value. What must be done differently? gordie you must put the script in the Text Editor in blender and press the Run script button. $\endgroup$
    – Arkhangels
    Nov 26, 2020 at 21:16

You must log in to answer this question.

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