# Driver variable prop (ID-block) : referencing the current object

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.

• So this is what I need to put in the Path field, and leave the Prop field empty ? – gordie Oct 27 '16 at 14:06

## 1 Answer

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

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?

• I can confirm there was no 'use self' option in Blender 2.77. – gordie Oct 31 '16 at 12:23
• 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 – gordie Oct 31 '16 at 12:43