Revit Link Instance from Revit link Document

Is it possible to retrieve Revit Link Instance from Revit link Document.I know that reverse is possible using RevitLinkInsance.GetLinkDocument.

With the infinite number of documents available, it’s pretty much a certainty that any given document will not have a link instance in a given file. What input would you provide to ensure some degree of overlap without first querying the content in the document?

It may be that you want to pull the transmission data from a given .rvt, and get all the paths from there. This will be faster then querying the links as you can do this for any .RVT without opening the file (TransmissionData.ReadTransmissionData method). From there you can GetAllExternalFileReferenceIds, use that to GetLastSavedReferenceData, and use the ExternalReference object which that returns to GetAbsolutePath.

1 Like

Hi,
an idea using the hashcode document


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 Autodesk.Revit.DB as DB

#import net library
from System import Array
from System.Collections.Generic import List, IList, Dictionary
clr.AddReference("System.Core")
clr.ImportExtensions(System.Linq)

#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 for x in allsDocs if x.IsLinked ]
linkdocsTitle = [d.Title for d in linkdocs]


def get_RvtLinkInstance(check_doc):
	linkInstance = FilteredElementCollector(doc).OfClass(DB.RevitLinkInstance) \
												.Where(lambda x : x.GetLinkDocument() is not None \
												and x.GetLinkDocument().GetHashCode() == check_doc.GetHashCode()).First()
	return linkInstance
	
OUT = linkdocsTitle, [get_RvtLinkInstance(i)for i in linkdocs]
4 Likes