Get filepath of linked CAD file (non-rvt file)

Get filepath of linked CAD file (non-rvt file)

dante.van.wettum
Advocate Advocate
2,725 Views
2 Replies
Message 1 of 3

Get filepath of linked CAD file (non-rvt file)

dante.van.wettum
Advocate
Advocate

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);
                }
Accepted solutions (1)
2,726 Views
2 Replies
Replies (2)
Message 2 of 3

dante.van.wettum
Advocate
Advocate
Accepted 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.

Message 3 of 3

jeremytammik
Autodesk
Autodesk

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



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes