How to collect elements from link visible in a view

I’m creating a script to tag elements from link in host project in a section view. I’m using node from GeniusLoci called SelectByCategoryInHostView to collect elements from link, but it doesn’t give me all elements visible in the view from linked model, just some of them. What is wrong with that?
image

@PiotrB ,

you can do in python

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

# 🛒 collect doors from linked file
doors = FilteredElementCollector(doclnk, doc.ActiveView.Id).OfCategory(BuiltInCategory.OST_Doors).WhereElementIsNotElementType().ToElements()

OUT = doors

I’m getting error like this:
image

And I’d like to specify list of views instead of active view.

grafik

@PiotrB ,

when you run in Revit 2024, Dynamo has still a bug. ( i hope it will be solved with the next hotfix )

I use IronPython2, just install IronPython2 package, it should run!

KR

Andreas

The same for IronPython2

@PiotrB

did you download?

grafik

i see it is not change able
grafik

Make sure you reference library before copy and paste :

import clr
clr.AddReference('RevitAPI')
clr.AddReference('RevitServices.dll')

# Import Revit elements
from Autodesk.Revit.DB import FilteredElementCollector, BuiltInCategory

grafik

Yes, I did. Still isn’t working.

Sorry my bad, modified code

I recomend you should go here to see solution Filter Element from Linked Model only if visible in active view - #6 by c.poupin

1 Like

It doesn’t work on section.

Can you show me whole python code please?

1 Like

@PiotrB

import clr

clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
from Autodesk.Revit.DB.Structure import *

clr.AddReference('RevitAPIUI')
from Autodesk.Revit.UI import *

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

clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.GeometryConversion)
clr.ImportExtensions(Revit.Elements)

clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

doc = DocumentManager.Instance.CurrentDBDocument
uidoc=DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument

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

# 🛒 collect doors from linked file
doors = FilteredElementCollector(doclnk, doc.ActiveView.Id).OfCategory(BuiltInCategory.OST_Doors).WhereElementIsNotElementType().ToElements()

OUT = doors

Thanks.
It doesn’t work in section view:

@PiotrB

i run it on a floorplan (view) → active view

I’m looking for a way to collect elements from linked model visible on section view.

This method assumes the view is in the provided document.

There’s a different overload specifically for elements in a linked instance. Use that instead.
FilteredElementCollector Members (revitapidocs.com)

You can use a for loop on an input list to treat each view separately or to combine each view’s list of elements depending on what you want.

Sorry, don’t know how to use that

Great opportunity to learn then. We want to help but no one is going to do the work for you.

The method I linked is the same one you already have in your code, just with different inputs. It’s pretty well explained in the documentation. Give it a shot and see where it gets you.

If you don’t know how to use a for loop, then I’d suggest doing a little research either here in the forum or just on Google. Python for loops are a foundation of most applications and pretty straight forward. They just take a little practice.