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!

  • $\begingroup$ I don't have the time to test it right now, but have you tried self.scale.y? $\endgroup$ – user27640 May 28 '17 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 '17 at 14:32

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.

  • $\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 '17 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 '17 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 '17 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 '17 at 18:44
  • $\begingroup$ @alterdings Consider asking a separate question, explaining why you want to switch a material node property based on the object scale. There could be other solutions than drivers (at the moment Animation Nodes come into my mind, but there might be trivial approaches to the problem). $\endgroup$ – aliasguru May 28 '17 at 18:51

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.