I have a situation where I have linked models inside of linked models and am trying to access the elements within that deepest level of linked model. I can get the first level of linked elements using the SteamNodes or Archilab nodes but can’t seem to get down to the next nested level of elements.
The Get Linked RVT Documents node returns items for each link and sub-link but then when I use Elements.GetFromLinkedFile, I only get elements that are in the highest/first level of linked model.
import clr
#import Revit API
clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
#Get Important vars
doc = DocumentManager.Instance.CurrentDBDocument
lstRvtlinkName = IN[0]
out = []
fecLnkInstace = FilteredElementCollector(doc).OfClass(RevitLinkInstance).ToElements()
for rvtLkinst in fecLnkInstace:
lnkType = doc.GetElement(rvtLkinst.GetTypeId())
if lnkType.IsNestedLink:
if Element.Name.GetValue(lnkType) in lstRvtlinkName:
linkDoc = rvtLkinst.GetLinkDocument()
fecWallNest = FilteredElementCollector(linkDoc).OfClass(Wall).WhereElementIsNotElementType().ToElements()
out.append([lnkType, rvtLkinst, linkDoc, fecWallNest])
OUT = out
Hi @c.poupin thank you for your great solution, it’s works like a charm but it’s still possible use it in the case of the nested links “GO_RVT1.rvt” file is set to Overlay (not Attachment) in the “RVT level 1.rvt” file? I have unespected error when I try get “GetLinkDocument()” from the nested links set Overlay. Maybe it’s a bug?
Hi @c.poupin thank you very much for your quick and accurate answer and for your time, so if I understand correctly actually from my main project I can get only Name, linkInstance and ID of my nested link set to Overlay, and I can’t get his Document with python ?
yes, because the model (and the associated document) is not loaded in the current doc
you can check list of loaded documents with Application.Documents
import clr
import sys
import System
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
import Autodesk.DesignScript.Geometry as DS
#import Revit API
clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *
#import transactionManager and DocumentManager (RevitServices is specific to Dynamo)
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
allsDocs = DocumentManager.Instance.CurrentUIApplication.Application.Documents
linkDocs = {x.Title : x for x in allsDocs if x.IsLinked}
no_linkDocs = {x.Title : x for x in allsDocs if not x.IsLinked}
OUT = no_linkDocs, linkDocs
here 2 examples (with a single open project file and a single RevitLinkType instance)
Hi @c.poupin , thank you very much for your precise and the very detailed reply, it’s very helpful. Thanks for your assistance. Have a good day. Cheers