File Path for Linked CAD


I’m trying to create a tool that re-path Linked CAD. However, I am stuck on getting the file path of the import instances (it’s part of the workflow), which confuses me because I use the same method in Dynamo Python and it works…

Here is my code:

dwgs = DB.FilteredElementCollector(revit.doc)\

for dwg in dwgs:
    if dwg.IsLinked:
        Ref = dwg.GetExternalFileReference()

and the error I got is “This Element does not represent an external file.”

Would you mind posting the whole code and the stack trace to make sure where the error is.

I believe your collector is incorrect -
I had written this code a while back - check if this works for you

allcadlinks = list(FilteredElementCollector(doc).\
for cadlink in allcadlinks:
    file_path = cadlink.GetExternalFileReference().GetPath()
    file_path = ModelPathUtils.ConvertModelPathToUserVisiblePath(file_path)
1 Like

Awesome! Works perfectly! Thanks you!