Hi
I have a list of Revit elements and I would to create a single Bounding Box around all elements in my list.
Could you please let me know how to that?
I do appreciate your help in advance.
Regards,
Farshid
Hi
I have a list of Revit elements and I would to create a single Bounding Box around all elements in my list.
Could you please let me know how to that?
I do appreciate your help in advance.
Regards,
Farshid
Geometry has nodes for singular and multiple geometries. You can convert your elements to geometry and use that instead.
# Import Namespace References
import clr,sys
# Revit API
clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *
# Flatten a source list
def flat(source):
result = []
def flatten_sequence(seq):
for item in seq:
if isinstance(item, (list, tuple, set)) and not isinstance(item, str):
flatten_sequence(item)
else:
result.append(item)
flatten_sequence(source)
return result
# Create a bounding box around multiple elements
def multi_element_bbox(elements):
point_list= []
for e in elements:
element_bbox= e.BoundingBox
point_list.append(element_bbox.MinPoint)
point_list.append(element_bbox.MaxPoint)
flattend_point_list = flat(point_list)
return BoundingBox.ByGeometry(plist)
OUT = multi_element_bbox(IN[0])
Collect the min and max points of each elements bounding box and use the points to create a new bounding box. If you want alignment to ‘best fit’ the bounding box to the geometry itself then you will need to use a slightly different approach.