Revit API_getting the Doors from Room with intersection

Hi All, I know there’s a node from Clockwork that gets the Door from Rooms but I would want to replicate it via Revit API as I would need to deploy it from other consultants via PyRevit and do something else with the parameters once I get the doors.

I have a code that gets the boundary of the room, the boundary of door instance and then find the doors via intersection. But for whatever reason it doesn’t work and it’s not giving me anything. Appreciate your help in advance.

from Autodesk.Revit.DB import *
from pyrevit import forms, revit

import clr
clr.AddReference("System")
from System.Collections.Generic import List

doc         = __revit__.ActiveUIDocument.Document
uidoc       = __revit__.ActiveUIDocument
app         = __revit__.Application
selection   = __revit__.ActiveUIDocument.Selection

active_view     = doc.ActiveView
active_level    = doc.ActiveView.GenLevel

with forms.WarningBar(title='Pick an element:'):
    room_element = revit.pick_element()

element_category          = room_element.Category.Name

if element_category != 'Rooms':
    forms.alert('Please pick a Room', exitscript=True)

selected_room = doc.GetElement(room_element.Id)
rm_boundary_segments = selected_room.GetBoundarySegments(SpatialElementBoundaryOptions())
doors_in_room = FilteredElementCollector(doc, active_view.Id).OfCategory(BuiltInCategory.OST_Doors).WhereElementIsNotElementType().ToElements()

rm_curve_lst = []
for segment in rm_boundary_segments:
    for line in segment:
        curve = line.GetCurve()
        rm_curve_lst.append(curve)

door_lst = []
for door in doors_in_room:
    door_location = door.Location
    if isinstance(door_location, LocationCurve):
        door_curve = door_location.Curve
        for curve in rm_curve_lst:
            intersection_result = curve.Intersect(door_curve)
            if intersection_result:
                door_lst.append(door)

print(len(door_lst))

I don’t think door 's location is LocationCurve.
door.Location alway return a XYZ (a point), for that reason: “isinstance(door_location, LocationCurve): = Flase” and then nothing appended to your list.

The easiest you just try to remove 2 row

"    if isinstance(door_location, LocationCurve):
        door_curve = door_location.Curve"

from your code, change door_curve in intersection_result = curve.Intersect(door_curve) to door_location and it will work

hi @thanhdatp297GRTHP thanks for looking, tried your suggestion but it’s giving me this

TypeError: expected Curve, got LocationPoint

You can try an other way, use both property Fromroom and Toroom

Creat a list of value Fromroom and Toroom for each Door and check is it contain with your room. If true, append this to your list

1 Like

alright thanks, will try this on weekend and see where it’ll take me.