# Beginner issue with getting a Driver to refer to "self" so I can link it to many objects

I'm trying to get an object to scale with its distance to another object, so I can then link the driver to the rest of the 639 objects in the collection.

I need it to somehow refer to itself, rather than explicitly selecting the object, so that when I link the driver, each of the linked objects will scale individually with their own proximity to the sphere. The intention is for each of the hexagonal objects to scale down when the sphere gets close.

In this thread, one answer says that if Use Self is checked, I can do the distance measurement in the expression itself if I use Single Property and use the sphere's matrix.world as the Object, but matrix.world isn't accepted when I try this.

In addition, is there a way I can get the driver to control XYZ scale so I don't need to use 3 drivers?

Attaching my blend file as requested. In this file, the driver is working correctly, but that's by specifying icosphere.083 as Object 2. I need it to work by somehow referring to "self" or "this object", so I can link the driver to other objects and have it work per object.

• Hello ! It's matrix_world and not matrix.world are you sure you used the correct expression ? Dec 6 '21 at 9:11
• matrix_world is also not accepted in the path field: i.imgur.com/i1mOpJc.png Dec 6 '21 at 10:25
• can u provide blend file? then i would check it out Dec 6 '21 at 10:27
• I've added a link to the blend file in the OP. Dec 6 '21 at 10:37

I noticed in your file that you had had a go with Geometry Nodes.. so as a side-note, this would be a possible arrangement:

The Length of the 'Relative' (i.e. owner's Object-Space) Location of the Object Info target is the distance from the GN-modified object-origin to the target object-origin. You can use some function of that for object-level proximity effects:

• Oh wow. I feel bad for Chris now. This actually suits me better than the script solution, because I can apply this to other things without feeling like I'm messing with powers beyond my ken. I hadn't fully tried to make it work with GNs, because I thought I'd need an individual GN for each hex. Now I love GNs even more than I already did. Thanks! I still need to learn scripting :P Dec 6 '21 at 14:41

you can use this script:

import bpy

# two sample functions
def calcDistance(object):

location2 = bpy.context.scene.objects["AssaultSphere"].location
print("loc2", location2)
location1 = object.location
print("loc1", location1)
distance = (location2 - location1).length

print(distance * 3)

return distance

# Add functions defined in this script into the drivers namespace.
bpy.app.driver_namespace["calcDistance"] = calcDistance


driver settings:

result:

• That is excellent, and works very well. Thank you very much. I can understand most of the script, but it's beyond my ability to arbitrarily replicate. I knew this would end up with me having to learn Python, but didn't expect it so soon. Dec 6 '21 at 11:25
• Glad I could help. Dec 6 '21 at 11:26
• I just can say from my personal experience: you can do a lot just with Blender - but you can do a lot more with python…‼️👍🏻🤗 Dec 6 '21 at 11:28