Linked rooms visible in ActiveView of current doc

Hello, please advise on how to get linked rooms visible in ActiveView.

From a reference dynamo manual I saw a method for doing this using solids but I wasn’t very successful at intersecting the room solids with the Active View solid (bounding box maybe?)

My other approach then has become this one:


# Access the document of the link
linkDocu = link.GetLinkDocument() # link is of type 'RevitLinkInstance'

# Get linked rooms
cat = DB.BuiltInCategory.OST_Rooms
filter = DB.ElementCategoryFilter(cat)
Type = doc.GetElement(link.GetTypeId())

if RevitLinkType.IsLoaded(doc, Type.Id):
    cuartos = DB.FilteredElementCollector(linkDocu).WherePasses(filter).WhereElementIsNotElementType().ToElements() 

print(len(cuartos))  # Check: 986 rooms in the link. OK cool but I just want the ones visible in the active view!!

# Tried the overload of FEC constructor "Autodesk.Revit.Exceptions.ArgumentException: viewId is not a view"
test = DB.FilteredElementCollector(linkDocu, doc.ActiveView.Id).WherePasses(filter).WhereElementIsNotElementType().ToElements() 

# Using quick filters doesnt work either, "Autodesk.Revit.Exceptions.ArgumentException: viewId is not valid for element iteration, because it has no way of representing drawn elements.  Many view templates will fail this check."
qk_Cat_filter1 = DB.ElementCategoryFilter(DB.BuiltInCategory.OST_Rooms) 
qk_Cat_filter2 = DB.VisibleInViewFilter(linkDocu, cuartos[0].Id, False) 

# Also tried passing LinkElementId but same error
# r_ID = LinkElementId(link.Id,cuartos[0].Id)


@Kervin ,

i did this approche… it works! i used FirstElement Methode because i have in my example just one


linked = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_RvtLinks).WhereElementIsNotElementType().FirstElement()
linkDoc = linked.GetLinkDocument()

all_rooms = FilteredElementCollector(linkDoc, activeView).OfCategory(BuiltInCategory.OST_Rooms).WhereElementIsNotElementType().ToElements()

names = [i.get_Parameter(BuiltInParameter.ROOM_NAME).AsString() for i in all_rooms]

for i in names:
    print(i)

these are my settings

doc = __revit__.ActiveUIDocument.Document
uidoc = __revit__.ActiveUIDocument
app = __revit__.Application
activeView = doc.ActiveView.Id

KR

Andreas

1 Like

Thanks @andreasd811 I tried your code but I still get the same error. I always thought FilteredElementCollector(linkDoc, activeView) does not work for link documents? Also does your link have multiple rooms in multiple floors or just in that floor? That might be something to look at also

1 Like

@Kervin ,

in my test file just in this level. can you post the error message, to replicate the error.

KR

Andreas

I get the error “Autodesk.Revit.Exceptions.ArgumentException: viewId is not a view” when passing it to FilteredElementCollector(linkDoc, activeView).

Because of this limitation I have to collect all the rooms in the link instead of just in the view which is what I really want

1 Like

@Kervin ,

just scip the id

activeView = doc.ActiveView     #insteat of doc.ActiveView.Id

… i tested you are right i can only get all rooms, he get ViewPlans it needs a reference i can just switch between Id and Object.
KR

Andreas