__title__ = "Find Intersecting Rooms&Areas"
__doc__ = """Date = 18.04.2024
__________________________
Description:
Find Intersecting Rooms&Areas and write Area.Name to Room.Name
(Adjust to your own needs)
_____________________________________________________________________
How-To:
- Run the Tool
- Select AreaScheme of desired Areas
_____________________________________________________________________
Author: Erik Frits"""
from Autodesk.Revit.DB import *
from Autodesk.Revit.DB.Architecture import Room
from pyrevit import forms
uidoc = __revit__.ActiveUIDocument
doc = __revit__.ActiveUIDocument.Document
def create_area_solid(area):
area_boundary = area.GetBoundarySegments(SpatialElementBoundaryOptions())
if area_boundary:
if len(area_boundary) == 0:
return None
profile = CurveLoop()
for curve in area_boundary[0]:
profile.Append(curve.GetCurve())
extrusion_height = 10.0
return GeometryCreationUtilities.CreateExtrusionGeometry([profile], XYZ.BasisZ, extrusion_height)
def is_point_inside_solid(point, solid):
line = Line.CreateBound(point, XYZ(point.X, point.Y, point.Z + 0.01))
tolerance = 0.00001
opts = SolidCurveIntersectionOptions()
opts.ResultType = SolidCurveIntersectionMode.CurveSegmentsInside
sci = solid.IntersectWithCurve(line, opts)
for i,x in enumerate(sci):
curve = sci.GetCurveSegment(i)
pt_start = curve.GetEndPoint(0)
pt_end = curve.GetEndPoint(1)
if point.IsAlmostEqualTo(pt_start, tolerance) or point.IsAlmostEqualTo(pt_end, tolerance):
return True
from collections import defaultdict
rooms = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Rooms).WhereElementIsNotElementType().ToElements()
all_areas = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Areas).WhereElementIsNotElementType().ToElements()
dict_areas = defaultdict(list)
for area in all_areas:
dict_areas[area.AreaScheme.Name].append(area)
from pyrevit import forms
sel_area_scheme = forms.SelectFromList.show(dict_areas.keys(), button_name='Select AreaScheme')
if not sel_area_scheme:
forms.alert('No AreaScheme was selected. Please Try Again')
areas = dict_areas[sel_area_scheme]
t = Transaction(doc, "Update Rooms")
t.Start()
for area in areas:
try:
area_solid = create_area_solid(area)
if area_solid:
for room in rooms:
room_point = room.Location.Point
if is_point_inside_solid(room_point, area_solid):
room.Name = Element.Name.GetValue(area)
except:
import traceback
print(traceback.format_exc())
t.Commit()