Here are a few utility nodes for Revit Links that I created to help go back and forth between RevitLinkTypes, RevitLinkInstances and Revit Link Documents and get some basic attributes. This Post may be updated over time, so be sure to visit now and then to see if there are any updates.
RevitLinkTypes
Link.GetRevitLinkTypes (Py)
Gets all the RevitLinkTypes in the current document and returns the RevitLinkTypes found, along with their respective model Filepaths and the model names.
import clr import sys pyt_path = r'C:\Program Files (x86)\IronPython 2.7\Lib' sys.path.append(pyt_path) import os import ntpath clr.AddReference("RevitServices") import RevitServices from RevitServices.Persistence import DocumentManager doc = DocumentManager.Instance.CurrentDBDocument clr.AddReference("RevitAPI") from Autodesk.Revit.DB import * rlTypes = [] fPaths = [] names = [] rvtLinkTypes = FilteredElementCollector(doc).OfClass(RevitLinkType) if rvtLinkTypes: for rlt in rvtLinkTypes: rlTypes.append(rlt) efr = rlt.GetExternalFileReference() if rlt.PathType == PathType.Relative: fPath = os.path.join(os.path.dirname(doc.PathName),ModelPathUtils.ConvertModelPathToUserVisiblePath(efr.GetPath())) else: fPath = ModelPathUtils.ConvertModelPathToUserVisiblePath(efr.GetPath()) fPaths.append(fPath) names.append(ntpath.basename(fPath)) OUT = rlTypes, fPaths, names
RevitLinkType.GetNames (Py)
Gets the model name from the given RevitLinkTypes
import clr import sys pyt_path = r'C:\Program Files (x86)\IronPython 2.7\Lib' sys.path.append(pyt_path) import os import ntpath clr.AddReference("RevitServices") import RevitServices from RevitServices.Persistence import DocumentManager from RevitServices.Transactions import TransactionManager doc = DocumentManager.Instance.CurrentDBDocument clr.AddReference("RevitAPI") from Autodesk.Revit.DB import * def tolist(obj1): if hasattr(obj1,"__iter__"): return obj1 else: return [obj1] def GetModelNameFromRevitLinkType(rlt): efr = rlt.GetExternalFileReference() fPath = ModelPathUtils.ConvertModelPathToUserVisiblePath(efr.GetPath()) return ntpath.basename(fPath) rvtLinkTypes = tolist(UnwrapElement(IN[0])) outList = [] for rlt in rvtLinkTypes: outList.append(GetModelNameFromRevitLinkType(rlt)) OUT = outList
RevitLinkType.GetModelPath (Py)
Gets the model Filepath from the given RevitLinkTypes.
import clr import sys pyt_path = r'C:\Program Files (x86)\IronPython 2.7\Lib' sys.path.append(pyt_path) import os import ntpath clr.AddReference("RevitServices") import RevitServices from RevitServices.Persistence import DocumentManager from RevitServices.Transactions import TransactionManager doc = DocumentManager.Instance.CurrentDBDocument clr.AddReference("RevitAPI") from Autodesk.Revit.DB import * def tolist(obj1): if hasattr(obj1,"__iter__"): return obj1 else: return [obj1] def GetModelNameFromRevitLinkType(rlt): pt = rlt.PathType efr = rlt.GetExternalFileReference() if pt == PathType.Relative: return os.path.join(os.path.dirname(doc.PathName),ModelPathUtils.ConvertModelPathToUserVisiblePath(efr.GetPath())) else: return ModelPathUtils.ConvertModelPathToUserVisiblePath(efr.GetPath()) rvtLinkTypes = tolist(UnwrapElement(IN[0])) outList = [] for rlt in rvtLinkTypes: outList.append(GetModelNameFromRevitLinkType(rlt)) OUT = outList
RevitLinkType.IsLoaded (Py)
Determines if the given RevitLinkTypes are loaded.
import clr import sys pyt_path = r'C:\Program Files (x86)\IronPython 2.7\Lib' sys.path.append(pyt_path) import os import ntpath clr.AddReference("RevitServices") import RevitServices from RevitServices.Persistence import DocumentManager from RevitServices.Transactions import TransactionManager doc = DocumentManager.Instance.CurrentDBDocument clr.AddReference("RevitAPI") from Autodesk.Revit.DB import * def tolist(obj1): if hasattr(obj1,"__iter__"): return obj1 else: return [obj1] rvtLinkTypes = tolist(UnwrapElement(IN[0])) outList = [] for rlt in rvtLinkTypes: if RevitLinkType.IsLoaded(doc,rlt.Id): outList.append(True) else: outList.append(False) OUT = outList
RevitLinkType.PathType (Py)
Gets the Revit Links Path Type given a Revit Link Type. For example, whether the Link Type is Absolute or Relative.
import clr import sys pyt_path = r'C:\Program Files (x86)\IronPython 2.7\Lib' sys.path.append(pyt_path) import os import ntpath clr.AddReference("RevitServices") import RevitServices from RevitServices.Persistence import DocumentManager from RevitServices.Transactions import TransactionManager doc = DocumentManager.Instance.CurrentDBDocument clr.AddReference("RevitAPI") from Autodesk.Revit.DB import * def tolist(obj1): if hasattr(obj1,"__iter__"): return obj1 else: return [obj1] rvtLinkTypes = tolist(UnwrapElement(IN[0])) outList = [] for rlt in rvtLinkTypes: if rlt: outList.append(rlt.PathType) else: outList.append(None) OUT = outList
RevitLinkType.GetInstance (Py)
Gets the RevitLinkInstance from the RevitLinkType. If the Revit Link is unloaded then it will return null for that RevitLinkType.
import clr import sys pyt_path = r'C:\Program Files (x86)\IronPython 2.7\Lib' sys.path.append(pyt_path) import os import ntpath clr.AddReference("RevitServices") import RevitServices from RevitServices.Persistence import DocumentManager from RevitServices.Transactions import TransactionManager doc = DocumentManager.Instance.CurrentDBDocument clr.AddReference("RevitAPI") from Autodesk.Revit.DB import * def tolist(obj1): if hasattr(obj1,"__iter__"): return obj1 else: return [obj1] def GetModelNameFromRevitLinkType(rlt): efr = rlt.GetExternalFileReference() fPath = ModelPathUtils.ConvertModelPathToUserVisiblePath(efr.GetPath()) return ntpath.basename(fPath) def GetModelNameFromRevitLinkInstance(rli): fPath = rli.GetLinkDocument().PathName return ntpath.basename(fPath) rvtLinkTypes = tolist(UnwrapElement(IN[0])) outList = [] rvtLinkInsts = FilteredElementCollector(doc).OfClass(RevitLinkInstance) for rlt in rvtLinkTypes: l = None for rli in rvtLinkInsts: try: if GetModelNameFromRevitLinkType(rlt) == GetModelNameFromRevitLinkInstance(rli): l = rli break except: continue outList.append(l) OUT = outList
RevitLinkType.Reload
Reload or ReloadFrom the Revit Link given RevitLinkTypes and optional input parameters. Click here for code as it is detailed in another post.
RevitLinkInstance
RevitLinkInstance.GetDocument (Py)
Get the Document of the RevitLinkInstance. You can use this Document thereafter to query or extract Element data.
import clr clr.AddReference("RevitServices") import RevitServices from RevitServices.Persistence import DocumentManager clr.AddReference("RevitAPI") import Autodesk from Autodesk.Revit.DB import * doc = DocumentManager.Instance.CurrentDBDocument def tolist(obj1): if hasattr(obj1,"__iter__"): return obj1 else: return [obj1] rvtLinkInsts = tolist(UnwrapElement(IN[0])) outList = [] for rli in rvtLinkInsts: if rli: outList.append(rli.GetLinkDocument()) else: outList.append(None) OUT = outList
RevitLinkInstance.GetRevitLinkType (Py)
Gets the RevitLinkType associated with the given RevitLinkInstance.
import clr clr.AddReference("RevitServices") import RevitServices from RevitServices.Persistence import DocumentManager doc = DocumentManager.Instance.CurrentDBDocument clr.AddReference("RevitAPI") from Autodesk.Revit.DB import * def tolist(obj1): if hasattr(obj1,"__iter__"): return obj1 else: return [obj1] rvtLinkInsts = tolist(UnwrapElement(IN[0])) outList = [] for rli in rvtLinkInsts: if rli: outList.append(doc.GetElement(rli.GetTypeId())) else: outList.append(None) OUT = outList
Revit Link Document
Document.IsLinked (Py)
Determines if the Document given is a Linked Document.
import clr clr.AddReference("RevitServices") import RevitServices from RevitServices.Persistence import DocumentManager clr.AddReference("RevitAPI") from Autodesk.Revit.DB import * def tolist(obj1): if hasattr(obj1,"__iter__"): return obj1 else: return [obj1] docs = tolist(UnwrapElement(IN[0])) OUT = [d.IsLinked if d else False for d in docs]
Document.GetRevitLinkInstance (Py)
Gets the RevitLinkInstance associated with the given Document.
import clr import sys pyt_path = r'C:\Program Files (x86)\IronPython 2.7\Lib' sys.path.append(pyt_path) import os import ntpath clr.AddReference("RevitServices") import RevitServices from RevitServices.Persistence import DocumentManager doc = DocumentManager.Instance.CurrentDBDocument clr.AddReference("RevitAPI") from Autodesk.Revit.DB import * def tolist(obj1): if hasattr(obj1,"__iter__"): return obj1 else: return [obj1] def GetModelNameFromDocument(d): fPath = d.PathName return ntpath.basename(fPath) def GetModelNameFromRevitLinkInstance(rli): fPath = rli.GetLinkDocument().PathName return ntpath.basename(fPath) docs = tolist(UnwrapElement(IN[0])) outList = [] rvtLinkInsts = FilteredElementCollector(doc).OfClass(RevitLinkInstance) for d in docs: if d: if d.IsLinked: for rli in rvtLinkInsts: try: if GetModelNameFromDocument(d) == GetModelNameFromRevitLinkInstance(rli): outList.append(rli) break except: continue else: outList.append(None) OUT = outList
The .dyn file with all the code and nodes can be downloaded from this DropBox link.
Note: This post may be periodically updated, please watch for updates.
July 10, 2018 at 6:44 pm
RevitLinkTypes node doesn’t work,,any idea ?
It gets Null
LikeLike
August 26, 2018 at 3:53 pm
Hi Abdullah.
Apologies for the delay in getting back to you. The wordpress template I am using is not the best for pre-formatted code (as you can see from the above) and when copying and pasting from the site it adds spaces to all lines and disregards tabs.
I will sort this at some point, but for the time being I have added a link to the .dyn file (with some updated content) which should sort your problem.
LikeLike
August 31, 2019 at 12:46 pm
Morning Dan,
Thank you very much for sharing your knowledge.
I am learning Dynamo and developing my own set for tools, and your content is really welcomed.
Antonio
LikeLike
September 15, 2019 at 10:32 am
Thanks Antonio! I’m glad you find this blog useful. Can’t wait to see your creations! 🙂
LikeLike