3
$\begingroup$

Quick question:

I'm trying to set up a driver which uses the Y-scale of whatever object the driver is on (which means that I don't want to use the Y-scale of a specific object, but rather any object).

I've read that the option "Use Self" is perfect this exact scenario, but I can't figure out how to use the self variable.

Someone suggested I use bpy.data.objects[self.id_data.user.name].scale.y in the python expression but that returns an ERROR: Invalid python expression.

What am I doing wrong? Thanks!

$\endgroup$
2
  • $\begingroup$ I don't have the time to test it right now, but have you tried self.scale.y? $\endgroup$
    – user27640
    May 28, 2017 at 14:20
  • $\begingroup$ Hi Duane, thanks for the fast reply, but that too yields the "ERROR: Invalid Python Expression" message. $\endgroup$
    – alterdings
    May 28, 2017 at 14:32

1 Answer 1

4
$\begingroup$

Using self in a driver is not as straight forward as thought, though it is really easy once you know where to put it. In short: In your driver, simply don't declare a variable, but use self in the expression itself to reference to the object. Check this screenshot here:

using self

This driver is hooked up to the scale.y property of an object. The important bit here is to check Use Self as indicated in the upper screenshot, so Blender actually declares what object self is pointing to automatically.

Now you can copy and paste this driver to any other object, it will take the scale.x from there as a driving source.

$\endgroup$
11
  • $\begingroup$ Hi aliasguru, thanks for your elaborate explanation! Unfortunately, this does not work either in my case, the Driver Value is still at 0 (although there's no Error message this time around). I should add that the scale.y value is animated on the object in question, should that pose a problem? $\endgroup$
    – alterdings
    May 28, 2017 at 16:58
  • $\begingroup$ @alterdings just to make sure, which property shall be driven by the y scale which is animated? I need to edit my answer to reflect that, as in my answer yscale is driven by xscale, so the other way around $\endgroup$
    – aliasguru
    May 28, 2017 at 17:54
  • $\begingroup$ In my case, the y scale drives the factor of a mix shader (see screenshot: imgur.com/a/smUh0) Thanks for taking the time to help me out! $\endgroup$
    – alterdings
    May 28, 2017 at 18:11
  • 1
    $\begingroup$ @alterdings That's the reason why you're having trouble. self in this case is not what you might think! If you read the tooltip on the Use_Self checkbox, you'll see that self can be an object, but also a bone, etc. Trouble is, that your driver lives on a Shader Node Tree. I'm not sure if self in this case is the Node Tree or the Material, but I'm almost certain it's not the object. And it can never be, because Blender allows materials to be shared across multiple objects. If now you had, say two objects using the exact same material, BOTH would try to alter the mix node of THE SAME material. $\endgroup$
    – aliasguru
    May 28, 2017 at 18:44
  • 2
    $\begingroup$ @Mentalist You can mix the workflows, as self is just a keyword referring back to the object. So your driver can have an expression like self.location.x - var where var is a custom variable pointing to the X location of the Empty for instance. To compute the distance you'd need to evaluate all three channels and do some vector math afaik $\endgroup$
    – aliasguru
    Mar 1, 2021 at 13:55

You must log in to answer this question.

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