Extract linked Rooms visible in host view?

Hello guys , is there a way to extract the rooms(from a linked document) that are visible in a host view project? i tried doing the bounding box intersection but as you can see the bounding box of the selected view is very far away from the rooms bounding boxes because of using scopeboxes, any other way?

Try using the OOTB node LinkInstance.AllElementsOfCategory.

Try this python option

import clr

clr.AddReference("RevitServices")
from RevitServices.Persistence import DocumentManager

clr.AddReference("RevitAPI")
from Autodesk.Revit.DB import *
from Autodesk.Revit.DB.Architecture import Room


def is_room_type(elem):
    return isinstance(elem, Room)


doc = DocumentManager.Instance.CurrentDBDocument

# Get link document with room by keyword in filename - NOTE: Case Sensitive
bip = ElementId(BuiltInParameter.ELEM_TYPE_PARAM)
pfrf = ParameterFilterRuleFactory.CreateContainsRule(bip, "Architect")
epf = ElementParameterFilter(pfrf)

link_instance = (
    FilteredElementCollector(doc)
    .OfClass(RevitLinkInstance)
    .WherePasses(epf)
    .FirstElement()
)
link_doc = link_instance.GetLinkDocument()

# Bounding Box Filter
crop_box = doc.ActiveView.CropBox
outline = Outline(crop_box.Min, crop_box.Max)
bb_inside = BoundingBoxIsInsideFilter(outline)
bb_intersects = BoundingBoxIntersectsFilter(outline)

# SpatialElement works with the primary DB and is recommended
rooms_inside = (
    FilteredElementCollector(link_doc)
    .OfClass(SpatialElement)
    .WherePasses(bb_inside)
    .ToElements()
)
rooms_intersects = (
    FilteredElementCollector(link_doc)
    .OfClass(SpatialElement)
    .WherePasses(bb_intersects)
    .ToElements()
)

OUT = filter(is_room_type, rooms_inside), filter(is_room_type, rooms_intersects)

FilteredElementCollector Class

If you are using rvt 24 or above, you can stop doing things the hard way since FilteredElementCollector now accepts a linkId.

:exploding_head:
Using a category filter is neater as well

import clr

clr.AddReference("RevitAPI")
from Autodesk.Revit.DB import (
    BuiltInCategory,
    BuiltInParameter,
    ElementId,
    ElementParameterFilter,
    FilteredElementCollector,
    ParameterFilterRuleFactory,
)

clr.AddReference("RevitServices")
from RevitServices.Persistence import DocumentManager


doc = DocumentManager.Instance.CurrentDBDocument

active_view = doc.ActiveView.Id

# Get link document with rooms by keyword in filename - NOTE: Case Sensitive
bip = ElementId(BuiltInParameter.ELEM_TYPE_PARAM)
pfrf = ParameterFilterRuleFactory.CreateContainsRule(bip, "Architect")
epf = ElementParameterFilter(pfrf)

link_instance = (
    FilteredElementCollector(doc)
    .OfCategory(BuiltInCategory.OST_RvtLinks)
    .WherePasses(epf)
    .FirstElement()
    .Id
)

OUT = (
    FilteredElementCollector(doc, active_view, link_instance)
    .OfCategory(BuiltInCategory.OST_Rooms)
    .ToElements()
)

Check whether your LinkInstance has a transformation (it’s likely that your architectural model isn’t linked origin-to-origin); if so, you must account for this transformation in your code to correctly reposition the Room Solids or Room bounding boxes.