How to get the elements inside a boundingbox?

python

#1

Hello everyone. I am a new dynamo user. I successfully thicken a surface of a floor along Z direction, and apply a boundingbox to that extrusion. The question is, is there a node that I can use to return all the elements(even without being selected in dynamo) contained inside the box?’ Thx!


How to Re-assign Elements to Worksets based on Scope Boxes
Get rooms within element
#2

Hi Po Chun,

Can you drop screenshot of your work. It will helps others to understand your issue. Thanks :slight_smile:


#3

I am sorry. Actually what i want is to return the pipe elemnnts inside the boundingbox


#4

the dyn node


#5

Hi @pccheung

The node BoundingBox.Contains is probably what you’re looking for. It only works with points though :

In my example I used the midpoint of the location curves of the pipes…


#6


#7

Hi mostafa, Kulkul,
Thx for both of your comments. However, is there another way for locating the pipes WITHOUT SELECTING THEM, the only element I selected is the floor.

Thanks a lot.


#8

I my example I didn’t select them, I got them all from the pipe category with the “categories” and “all elements of category” nodes


#9

@Mostafa_El_Ayoubi I think @pccheung is looking to get elements (pipes) without using categories or selecting elements. I guess he wants to get elements inside boinding box without specifying.


#10

Ha ha, it’s true. I am sorry that i didn’t make the question clear. Indeed I m trying to check the headroom above the selected floor. In a real project, there will be beams, pipes, ducts, cable tray …etc above the floor. Do you mean I can only got all those stuff through categories node?

Really, thx for your efforts!


#11

Oh I see . Sorry for misunderstanding … I’m not sure how that could be done !


#12

You can do something like this:

With FilteredElementCollector you get all elements in the (active) view. And with BoundingBoxIsInsideFilter or BoundingBoxIntersectsFilter you can filter out the elements inside the bounding box:

##Python code:

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

#Preparing input from dynamo to revit
bb = IN[0].ToRevitType()
outline = Outline(bb.Min, bb.Max)
#filter = BoundingBoxIntersectsFilter(outline)
filter = BoundingBoxIsInsideFilter(outline)

collector = FilteredElementCollector(doc, doc.ActiveView.Id).WherePasses(filter)

OUT = [e.ToDSType(True) for e in collector]

##File:
getElementsInBB.dyn (7.8 KB)


Getting all Elements of type within a bounding box
#13

Dear Einar_Raknes,

Thank you very much. I am gonna try it out. It’s fascinating!!! THX!


#14

Dear Sir Einar_Raknes,

Sorry for being stupid, can me further explain to me what is the output of the python script note, because I use a watch node to check what it gives out, it shows me a null.


#15

Oh Sorry, I quit and restart, it returns to normal. Sorry Sorry.


#16

Hi,

Interesting topic. I have a similar question.
I have used this python script with a scope box and all works fine as long as i use the “Select model element” with one scope box. But i want to take this a step further by using categories to select all scope boxes. Then the issues starts. The script won´t run through.

So to my question… What am i doing wrong? Is it possible to repeat the script for each scope box?
I have tried to get around this but i do not manage to full fill my wish :slight_smile:

Is there anyone who has any ides what i´m doing wrong?

>


#17

I wrote this in another topic: How to make a pyton script work with a list as input


#18

Thanks for the fast reply.
Ok, so i have no experience with python or programming… i tried to read trough and understand witch part i should implement and i got this.
I did not work. Maybe you could point me in the right direction?

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 )

def ProcessParallelLists(_func, *lists):
return map( lambda *xs: ProcessParallelLists(_func, *xs) if all(type(x) is list for x in xs) else _func(*xs), *lists )

#Preparing input from dynamo to revit
def Unwrap(item):
return UnwrapElement(item)

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

if isinstance(IN[0], list):
bb = ProcessList(Unwrap, IN[0])
else:
bb = list(Unwrap(IN[0]))

bb = IN[0].ToRevitType()
outline = Outline(bb.Min, bb.Max)
filter = BoundingBoxIntersectsFilter(outline)
#filter = BoundingBoxIsInsideFilter(outline)

collector = FilteredElementCollector(doc, doc.ActiveView.Id).WherePasses(filter)

OUT = [e.ToDSType(True) for e in collector]

#19
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)

How to see what elements are in which scope box
Get all elements by View
Set Multiple Worksets to elements based on Scope Box Location
#20

Thank you Einar!
It works perfect!
You made my day!
:grin: