Get Elements from Nested Linked Models (Linked Models within Linked Models)

Hi,

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.

Capture|690x230

I hope I explained this clearly. Any help would be appreciated! Thanks,

Jason

Apply the concept of crossed lacing to your models for more control

Been down this road before and the behavior is not what is expected.

1 Like

Thanks for the reply. I think in this case, it might be easier to organize my files differently and avoid the issue all together.

2 Likes

Hello
a solution to search Elements only on nested Linked Models

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
4 Likes

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?


below some links, from @SeanP

and another from Revit API Forum

Thanks in advance. Have a good day Cheers

Hello @paris
when nested links are set to Overlay, their document are not loaded,
The link exists, but it will not be brought along.
from the api doc

1 Like

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 ?



)

Thank you very much for your assistance. Cheers

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)

1 Like

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

1 Like