Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

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

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
dante.van.wettum
2020 Views, 2 Replies

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

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);
                }
2 REPLIES 2
Message 2 of 3

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

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

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Rail Community