How to get the linked room of a element in the current doc?

Hello,

i stuck

i want to get from an element the room, the room is linked

#🌈 links
linked_docs = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_RvtLinks).WhereElementIsNotElementType().ToElements()
lnkInstance = [i for i in linked_docs if i.Name.Contains("AR")]

doclnk = lnkInstance[0].GetLinkDocument()



selection = uidoc.Selection #type: Selection



# Get selected floors or ask user to pick:
selectedIds = uidoc.Selection.GetElementIds()
# phase = doc.GetPhaseStatus(1)

ref_picked_objects = selection.PickObjects(ObjectType.Element)
picked_objects = [doc.GetElement(ref) for ref in ref_picked_objects]

phases = doc.Phases
phase = phases[phases.Size - 1]

print(phase)
print(doclnk)

points = []

for i in picked_objects:
    points.append(i.Location)

output = []

for i in points:
    if doclnk.GetRoomAtPoint(i) == None:
        output.append("No Room")
    else:
        output.append(doclnk.GetRoomAtPoint(i))

OUT = output


for i in points:
    if doclnk.GetRoomAtPoint(i) == None:
        output.append("No Room")
    else:
        output.append(doclnk.GetRoomAtPoint(i))

Disclaimer: I don’t know but I’ve been playing mindless computer games for the last 2 hours so thought I’d come on here :smiley:

Is β€˜i’ in points in the correct format?

Have you tried inputting a point (X, Y, Z) that you know is in the room to see what happens?

3 Likes
  • try to add the Point attribute
for i in picked_objects:
    points.append(i.Location.Point)
  • it is preferable to test all phases, unless you are certain that the rooms were created in the last phase

room = next((doc.GetRoomAtPoint(point, ph) for ph in doclnk.Phases if doclnk.GetRoomAtPoint(point, ph) is not None), None)

  • Lastly, it is possible that your lnkInstance has a transformation, in which case you should take this into account.
1 Like