How to get the Revit Links file path, type, instance of Autodesk Desktop Connector BIM360 in current project document?

How to get the Revit Links file path (local in Autodesk Desktop Connector), type, instance?

I usually give input of file path to get the links in the files but I want to do the reverse, so I got a file opened with linked Revit files and I would like to know the file path of the linked Revit files.

currently I am using this python script to get the revit links types and instances in separate lists, but I would like to add the file path of those. The difficulty is that the saved path is a cloud path, but I would like to get the path of the Autodesk Desktop of BIM360 in my local drive instead.

For this, I tried to get the File info with clockwork package but the central path indicated is in other server which is not my local drive, cloud path, I do not have access because it is a Clarity server.

Also I tried to find Revit files paths in the local drive with the Revit file names.


import clr

# Import DocumentManager and TransactionManager
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager

# Import RevitAPI
clr.AddReference("RevitAPI")
import Autodesk
from Autodesk.Revit.DB import *

doc = DocumentManager.Instance.CurrentDBDocument

# Import ToDSType(bool) extension method
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)

coll = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_RvtLinks).WhereElementIsNotElementType().ToElements()

insts, types = [], []

for c in coll:
	insts.append(c.ToDSType(True))
	types.append(doc.GetElement(c.GetTypeId()))

OUT = [insts,types]

Check the ExternalFileReference class, in particular this method : GetAbsolutePath Method

1 Like

use like that :

# Load the Python Standard and DesignScript Libraries
import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
# Import DocumentManager and TransactionManager
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
paths = []
def GetExtFileRefPath(item):
	try :
	   dirRefs = item.GetExternalResourceReferences()
	   for i,v in enumerate(dirRefs):
	       paths.append(v.Value.InSessionPath)
	   return paths
	except Exception as e: return e.ToString()
doc = DocumentManager.Instance.CurrentDBDocument
items = FilteredElementCollector(doc).OfClass(RevitLinkType).ToElements()
OUT = [GetExtFileRefPath(x) for x in items]

Home.dyn (3.5 KB)

1 Like

hello @chuongmep many thanks, I tried and result is same list of path of the revit linked files in current project, but if I got 20 links this list is repeated 20 times, I just need one path by Revit file

you can try modify function GetExtFileRefPath return a path in fist index value of dictionary, it will be work in case of you.

Like that :

# Load the Python Standard and DesignScript Libraries
import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
# Import DocumentManager and TransactionManager
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
paths = []
def GetExtFileRefPath(item):
	try :
	   dirRefs = item.GetExternalResourceReferences()
	   for i,v in enumerate(dirRefs):
	       return v.Value.InSessionPath
	except Exception as e: return e.ToString()
doc = DocumentManager.Instance.CurrentDBDocument
items = FilteredElementCollector(doc).OfClass(RevitLinkType).ToElements()
OUT = [GetExtFileRefPath(x) for x in items]
1 Like

it looks great, I am looking the result of the last script, aparently the list of link paths are sorted alphabetically but it is not the case in some file paths. Would it be possible to give to the python script an input of revit link types/instances?

I noticed file directories appear as β€œ/” instead of β€œ\”

you can use GetTypeId Method if want get from revit link instance.

with path in bim360, you can use origin path to connect with forge hub or some thing relative path, why we need care β€œ/” or β€œ\” ?

the script shown at the beggining is using this, but I would like to get the file path associated to each revit link type/instance

I don’t understand what you want because it similar, you can see some example like that in case you want try check for types and instances of rvtlinked

3 Likes

I agree it is very similar but how to know what Revit link type or instance is part of the script output? I would create a sublist first of revit link type/instances and other sublist of revit link paths, so I can create a dictionary. Following your last script screenshot would be something like: OUT=[instances,types,linkInstancePath,linkTypePath]