Sorting Elements by Bounding Box

I have 80 scope boxes which I’m using to locate equipment through my job. I can sort elements in dynamo with bounding box nodes but I don’t want to do 80 node group repetitions for each bounding box to see whether the elements is true/false.

Is there a way to code in python the below workflow:

  1. Using the element geometry to cycle through each bounding box geometry and determine what bounding box it lies in
  2. Output the index of the bounding box so I can retrieve the associated scope box

From what I can see looking at other code its going to have the geometry of the element and bounding box as inputs and using a for loop find what box it’s in then retrieve the index.

Let me know if I’m thinking in the right direction

I sounds like the right direction but you should need a for loop inside a for loop.
You have two lists: one with the scope boxes and one with all the other elements. :slight_smile:

Go for it and post here if you’re having trouble.

While I know you asked for a python solution, I’d like to offer a node approach:

The custom nodes are from spring nodes. You certainly don’t need to repeat something 80 times to get the desired solution. Give it a try.

1 Like

Here is a really easy way using BimorphNodes plus its more efficient as it doesn’t need to convert the bounding boxes of the elements to ProtoGeometry nor use a ProtoGeometry method (which are usually slower than Revit API processes). Just match the index of your scope box with the index of the sub-list from the BoundingBox.GetElementsIntersect node and that is the list of elements inside or intersecting that scope box:

There are two issues though, which your requirements need to address:

  1. How do you handle elements which can be in more than 1 scope box?
  2. Rotated scope boxes?

In respect to no.2 bounding boxes are always axis-aligned, so if you want to consider the scope box in its rotated position to perform the containment test, then you would need to convert it to a solid and then you can use a node such as Element.IntersectsSolid to perform the containment check.

No I do like a node a solution as don’t know python. Everything after the bounding box intersection node I wasn’t aware of and exactly what I was looking for.

The only change to my code was I converted the element to points and used the bounding box contains node as I have alot of elements the intersect different scope boxes.

Yes point 1 is an issue for me as the elements I have intersect multiple scope boxes, hence why I use bounding box contains point node.

Will see if I can work it using the above approach