Collect all elements in a geometry

#1

Hi all,

I want to collect all the element strictly inside a geometry. I already found a node that collect all the element (not strictly) in a bounding box. The problem is that the bounding box can not always define the exact geometry as it is align with the axis. So I don’t want to create a Bounding Box. And also, this node takes all the elements inside the bb but also the ones that intersect the bb (but are not completly inside the bb), I only want the ones strictly inside my geometry.
Any help to change the script please ?
Here it is :

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)

Thanks !

0 Likes

#2

Could you tell where does this code come from and what you tried to change in it?
See also here how to paste code in a post:

0 Likes

#3

The code comes from this forum,
I tried to change the bounding box in a geometry and get the outlines of the geometry instead of the “(bb.Min, bb.Max)”,
I am not very good on python, just learning and so trying things.

0 Likes

#4

Please add the link to the original post and point to the lines you tried to change with some explanation around. Thanks :slight_smile:

0 Likes

#5

Have you tried to use a geometry.intersects node as a bool mask? Should be callable via Python.

Note that this will be much slower than the bounding box.contains node.

0 Likes