# Select all geometry touching a user selected object?

#1

I’ve never scripted before. I have a complex scene with many objects and selection is difficult. I’m dreaming of a script that selects those objects that are touching a user-selected object. I’m thinking maybe getting the bounding box of the first object then somehow selecting those objects that intersect that bounding box ? Depending on the geometry those might not actually be physically in contact with the first. just very close. I can figure out filtering options later, but that first part : pick object --> get bounding box --> get all scene objects --> filter by intersection with bounding box of first, has me stumped.
Can anyone kindly make me smarter ?

Thanks!

#2

in general the task is not simple. but if we do only world-oriented (or called non-oriented) bounding boxes:

``````fn findBBoxIntersected node nodes: =
(
fn getNodeBBox3 node =
(
bb = nodeGetBoundingBox node (matrix3 1)
box3 bb[1] bb[2]
)

if nodes == unsupplied do nodes = objects

b = getNodeBBox3 node

_nodes = for n in nodes where n != node collect
(
x = getNodeBBox3 n
if intersects b x then n else dontCollect
)

_nodes
)

findBBoxIntersected \$``````

The next in complexity:

1. finding the intersection of oriented bounding boxes.
2. finding by convex hulls (quick hull) intersection
3. finding by the actual geometry (which may have different implementations: grid, voxels, kd-tree, Rtree, etc.)

#3

By the way… I remember at least 3–4 threads on this forum related to this task.