Get Elements in Boundingbox not working (Python)

Hello all,

I’m trying to retrieve elements in a Boundingbox with an ‘old’ Python script, but where it worked before I now get an Empty List.
My knowledge of Python is very limited, so I hope someone on this forum can help me further?
I am using Revit 2023 and Dynamo 2.16

Thank you in advance!

import clr
clr.AddReference('RevitAPI')
clr.AddReference('System')
clr.AddReference('RevitNodes')
clr.AddReference('RevitServices')
import Revit
import RevitServices
from Autodesk.Revit.DB import *
from System.Collections.Generic import List
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
clr.ImportExtensions(Revit.Elements)
clr.ImportExtensions(Revit.GeometryConversion)
doc = DocumentManager.Instance.CurrentDBDocument

#Functions for list handling
def ProcessList(_func, _list):
   return map( lambda x: ProcessList(_func, x) if type(x)==list else _func(x), _list )

#Preparing input from dynamo to revit

def ToRevit(item):
	return item.ToRevitType(True)

if isinstance(IN[0], list):
	bblist = ProcessList(ToRevit, IN[0])
else:
	bblist = [ToRevit(IN[0])]

def collectElementsInBB(bb):
	outline = Outline(bb.Min, bb.Max)
	filter = BoundingBoxIntersectsFilter(outline)
	collector = FilteredElementCollector(doc, doc.ActiveView.Id).WherePasses(filter)
	return [e.ToDSType(True) for e in collector]

OUT = ProcessList(collectElementsInBB, bblist)

Can you post the RVT file to reproduce the issue? My gut says we have a coordinate system issue at play.

Just to clarify, your code is getting all elements that intersect with the bounding box and not just elements that are completely inside the bounding box.

Hi Jacob!

Unfortunately I can’t share the model for privacy reasons.
I have tried to simulate it in an empty Revit model, but the Python works strangely enough there…

indeed!

1 Like

seems related to a Dynamo conversion bug (unit conversion)

the coordinate values ​​shouldn’t be the same in my case (in meter project)

BUT it seems to me that ToRevitType() is not meant for converting geometry

it is therefore necessary

  1. extract the Min and Max points
  2. convert them with ToXyz()
  3. then use the DB. BoundingBoxXYZ constructor and set the min and the max
    BoundingBoxXYZ Constructor
    Max Property
    Min Property

The strange thing remains that if I try the same in an empty Revit template with a scope box and a few elements in it, it works flawlessly.
So the script apparently works, but not in the project in question.
Very weird…

i think i found the problem.

I found out that it just didn’t work on models that were very large.

So I set the Geometry Scaling in Dynamo to Extra Large and now it works again!