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.

RevitLinkUtils1.JPG

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

RevitLinkUtils2.JPG

 

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.

RevitLinkUtils3.JPG

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.

IsLoaded.JPG

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.

LinkType.JPG

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.

RevitLinkUtils5.JPG

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.

 

ReloadFromDetailed.JPG

RevitLinkInstance

RevitLinkInstance.GetDocument (Py)

Get the Document of the RevitLinkInstance. You can use this Document thereafter to query or extract Element data.

RevitLinkUtils6.JPG

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.

RevitLinkUtils7.JPG

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.

RevitLinkUtils8.JPG

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.

RevitLinkUtils9.JPG

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.

Advertisement