from Autodesk.Revit.UI.Selection import *
class LinkedRoomSelectionFilter(ISelectionFilter):
def __init__(self, doc):
self.doc = doc
def AllowElement(self, element):
return True
def AllowReference(self, reference, position):
revit_link_instance = self.doc.GetElement(reference.ElementId)
if isinstance(revit_link_instance, RevitLinkInstance):
linked_doc = revit_link_instance.GetLinkDocument()
linked_elem = linked_doc.GetElement(reference.LinkedElementId)
if linked_elem.Category.Id == ElementId(BuiltInCategory.OST_Rooms):
return True
selobject_link = uidoc.Selection.PickObjects(ObjectType.LinkedElement, LinkedRoomSelectionFilter(doc), 'Select rooms')
for ref in selobject_link:
revit_link_instance = doc.GetElement(ref.ElementId)
linked_doc = revit_link_instance.GetLinkDocument()
linked_elem = linked_doc.GetElement(ref.LinkedElementId)
print(linked_elem.Name)