0
$\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$
  • $\begingroup$ So this is what I need to put in the Path field, and leave the Prop field empty ? $\endgroup$ – gordie Oct 27 '16 at 14:06
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$
  • $\begingroup$ I can confirm there was no 'use self' option in Blender 2.77. $\endgroup$ – gordie Oct 31 '16 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 '16 at 12:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.