Selecting all objects closest to another?

Is there a way to select objects that are neighboring(closest) to another object through python?

import bpy

distance = 5.0
active_object = bpy.context.active_object

for other_object in bpy.data.objects:
    if (other_object.location - active_object.location).length < distance:
        other_object.select_set(True)
        
3 Likes

This can also be implemented in Animation Nodes.

1 Like

Should be doable with a kd-tree or bvh-tree.

1 Like