I am trying to retrieve the filepath of linked CAD files that are linked in the model. I try to do this specifially for all linked files that are not revit linked models.
But so far it seems like i am not capable of retrieving the filepath of a linked (non-rvt) file (.dwg's and such).
Is it possible to get the file path of linked files trough API ?
FilteredElementCollector col = new FilteredElementCollector(doc).OfClass(typeof(CADLinkType)); foreach (Element el in col) { try { CADLinkType link = doc.GetElement(el.Id) as CADLinkType; bool isLinkedFile = link.IsExternalFileReference(); if (isLinkedFile == true) { ExternalFileReference exFiRef = link.GetExternalFileReference(); ModelPath path = exFiRef.GetPath(); string pathString; if( path.ServerPath == true) { pathString = path.CentralServerPath; } else { pathString = path.ToString(); } TaskDialog.Show("Path", "RefType: "+exFiRef.ExternalFileReferenceType.ToString() + Environment.NewLine+ "Path: " + pathString); } } catch (Exception ex) { TaskDialog.Show("Error", ex.Message); }
Solved! Go to Solution.
Solved by dante.van.wettum. Go to Solution.
finally found it by using : ModelPathUtils.ConvertModelPathToUserVisiblePath(exFiRef.GetAbsolutePath());
apparently i was looking in the wrong places (members of ExternalFileReference, ImportInstance, and even looking into TransmissionData).
i just didnt came up with looking for ModelPathUtils.
Dear Dante,
Thank you for your query and sharing your solution.
Yes, indeed, as @Revitalizer keeps pointing out as well, the Revit API Util classes are often overlooked:
http://thebuildingcoder.typepad.com/blog/about-the-author.html#5.52
Thank you for bringing up yet another important use case.
Cheers,
Jeremy