external reference versus importinstance

external reference versus importinstance

phildebrandt
Enthusiast Enthusiast
927 Views
1 Reply
Message 1 of 2

external reference versus importinstance

phildebrandt
Enthusiast
Enthusiast
if(sel.Elements.Size == 1)
                {
                    System.Collections.IEnumerator es = sel.Elements.GetEnumerator();
                    es.MoveNext();
                    ImportInstance imp = es.Current as ImportInstance;
                    ExternalFileReference el = imp.GetExternalFileReference(); // errors here!!!
                    if (el != null)
                    {
                        directory = ModelPathUtils.ConvertModelPathToUserVisiblePath(el.GetAbsolutePath());
                    }
                }

I've been trying to get the file path of a DWG file that is linked into a Revit project. The code above always errors that the  ImportInstance is not an external reference but I know the file is linked not imported.

 

Does anyone know what the difference between an Importinstance and an externalfilereference is?

0 Likes
Accepted solutions (1)
928 Views
1 Reply
Reply (1)
Message 2 of 2

jeremy_tammik
Alumni
Alumni
Accepted solution

hi paul,

 

here is the answer that you provided yourself:

 

I managed to find a solution:

 

ImportInstance imp = es.Current as ImportInstance;

if (imp.IsLinked)

{

  ExternalFileReference el = ExternalFileUtils.GetExternalFileReference(actdoc, imp.GetTypeId());

  if (el != null)

    directory = ModelPathUtils.ConvertModelPathToUserVisiblePath(el.GetAbsolutePath());

}

 

I guess the GetExternalFileReference() isn’t supposed to be exposed in the ImportInstance class like I had tried previously.

 

cheers,

 

jeremy

--
Jeremy Tammik
Autodesk Developer Network
http://thebuildingcoder.typepad.com

 

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes