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: 

How to find pathname of linked dwg files ?

9 REPLIES 9
SOLVED
Reply
Message 1 of 10
pmeigneux
890 Views, 9 Replies

How to find pathname of linked dwg files ?

pmeigneux
Advocate
Advocate

Hi,

 

I'm using this code to find AutoCAD Dwg Links (3D or 2D) :

 

foreach (Category c in Doc1.Settings.Categories)
{
    if (c.Name.ToLower().EndsWith(".dwg"))
    {
        TaskDialog.Show("debug", "New ==>" + c.Name);
    }
}

 

But I cannot find the pathname.

 

Also if a dwg link is in a A.rvt linked to the Main.rvt, How to find the related father A.rvt file ? Actually we have a way to find all linked .dwg files at different levels, but we don<t know how to get their respective parents.

 

Philippe Meigneux.

0 Likes

How to find pathname of linked dwg files ?

Hi,

 

I'm using this code to find AutoCAD Dwg Links (3D or 2D) :

 

foreach (Category c in Doc1.Settings.Categories)
{
    if (c.Name.ToLower().EndsWith(".dwg"))
    {
        TaskDialog.Show("debug", "New ==>" + c.Name);
    }
}

 

But I cannot find the pathname.

 

Also if a dwg link is in a A.rvt linked to the Main.rvt, How to find the related father A.rvt file ? Actually we have a way to find all linked .dwg files at different levels, but we don<t know how to get their respective parents.

 

Philippe Meigneux.

9 REPLIES 9
Message 2 of 10
jeremytammik
in reply to: pmeigneux

jeremytammik
Autodesk
Autodesk

Dear Philippe,

 

Thank you for your query.

 

For the DWG files, one simple possible solution would be to use the operating system directory traversal tools to find the DWG file, assuming that you know that it is located within or underneath some specific directory, or collection of directories.

 

I am afraid that I am not aware of any other possibility right now.

 

I am somewhat surprised that I could not find a wish list item for this functionality, so I created one and asked the development team for ideas:

 

I submitted the wish list item CF-4080 [API wish: determine full pathname of linked dwg file] on your behalf for the functionality you suggest, as this issue requires exploration and possibly a modification to our software. Please make a note of this number for future reference.

 

You are welcome to request an update on the status of this issue or to provide us with additional information at any time quoting the wish list item number or this thread.

 

This issue is important to me. What can I do to help?

 

This issue needs to be assessed by our engineering team, and prioritised against all of the other outstanding change requests. Any information that you can provide to influence this assessment will help. Please provide the following where possible:

 

  • Impact on your application and/or your development.
  • The number of users affected.
  • The potential revenue impact to you.
  • The potential revenue impact to Autodesk.
  • Realistic timescale over which a fix would help you.
  • In the case of a request for a new feature or a feature enhancement, please also provide detailed Use cases for the workflows that this change would address.

 

This information is extremely important. Our engineering team have limited resources, and so must focus their efforts on the highest impact items. We do understand that this will cause you delays and affect your development planning, and we appreciate your cooperation and patience.

 

I hope this helps.

 

Best regards,

 

Jeremy



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

Dear Philippe,

 

Thank you for your query.

 

For the DWG files, one simple possible solution would be to use the operating system directory traversal tools to find the DWG file, assuming that you know that it is located within or underneath some specific directory, or collection of directories.

 

I am afraid that I am not aware of any other possibility right now.

 

I am somewhat surprised that I could not find a wish list item for this functionality, so I created one and asked the development team for ideas:

 

I submitted the wish list item CF-4080 [API wish: determine full pathname of linked dwg file] on your behalf for the functionality you suggest, as this issue requires exploration and possibly a modification to our software. Please make a note of this number for future reference.

 

You are welcome to request an update on the status of this issue or to provide us with additional information at any time quoting the wish list item number or this thread.

 

This issue is important to me. What can I do to help?

 

This issue needs to be assessed by our engineering team, and prioritised against all of the other outstanding change requests. Any information that you can provide to influence this assessment will help. Please provide the following where possible:

 

  • Impact on your application and/or your development.
  • The number of users affected.
  • The potential revenue impact to you.
  • The potential revenue impact to Autodesk.
  • Realistic timescale over which a fix would help you.
  • In the case of a request for a new feature or a feature enhancement, please also provide detailed Use cases for the workflows that this change would address.

 

This information is extremely important. Our engineering team have limited resources, and so must focus their efforts on the highest impact items. We do understand that this will cause you delays and affect your development planning, and we appreciate your cooperation and patience.

 

I hope this helps.

 

Best regards,

 

Jeremy



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

Message 3 of 10

Dale.Bartlett
Collaborator
Collaborator
Accepted solution

Unless I am misundertanding the question, this returns DWG link paths. I haven't looked at nested links. Dale

 

// collect all (immediate) external references in the model
                ICollection<ElementId> externalReferences = transData.GetAllExternalFileReferenceIds();
                int n = externalReferences.Count;

                // content += string.Format("has {0} external reference{1}{2}", n, PluralSuffix(n), DotOrColon(n));
                links = new List<string>(n);
                // DWG
                foreach (ElementId refId in externalReferences)
                {
                    ExternalFileReference extRef = transData.GetLastSavedReferenceData(refId);
                    // DWG
                    if (extRef.ExternalFileReferenceType == ExternalFileReferenceType.CADLink)
                    {
                        // get absolute path to check for validity
                        string lstrLinkFileNameAbsolute = ModelPathUtils.ConvertModelPathToUserVisiblePath(extRef.GetAbsolutePath());
                        links.Add(lstrLinkFileNameAbsolute);
                    }
                }



______________
Yes, I'm Satoshi.

Unless I am misundertanding the question, this returns DWG link paths. I haven't looked at nested links. Dale

 

// collect all (immediate) external references in the model
                ICollection<ElementId> externalReferences = transData.GetAllExternalFileReferenceIds();
                int n = externalReferences.Count;

                // content += string.Format("has {0} external reference{1}{2}", n, PluralSuffix(n), DotOrColon(n));
                links = new List<string>(n);
                // DWG
                foreach (ElementId refId in externalReferences)
                {
                    ExternalFileReference extRef = transData.GetLastSavedReferenceData(refId);
                    // DWG
                    if (extRef.ExternalFileReferenceType == ExternalFileReferenceType.CADLink)
                    {
                        // get absolute path to check for validity
                        string lstrLinkFileNameAbsolute = ModelPathUtils.ConvertModelPathToUserVisiblePath(extRef.GetAbsolutePath());
                        links.Add(lstrLinkFileNameAbsolute);
                    }
                }



______________
Yes, I'm Satoshi.
Message 4 of 10

jeremytammik
Autodesk
Autodesk

Cool!

 

Thank you, Dave!

 

Please confirm, Philippe.

 

Cheers,

 

Jeremy



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

0 Likes

Cool!

 

Thank you, Dave!

 

Please confirm, Philippe.

 

Cheers,

 

Jeremy



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

Message 5 of 10

Dale.Bartlett
Collaborator
Collaborator
DaLe



______________
Yes, I'm Satoshi.
0 Likes

DaLe



______________
Yes, I'm Satoshi.
Message 6 of 10
Anonymous
in reply to: Dale.Bartlett

Anonymous
Not applicable

sorry, mistake.

0 Likes

sorry, mistake.

Message 7 of 10

jeremytammik
Autodesk
Autodesk

Sorry, DaLe,

 

I know very well, but somehow my fingers went off on their own accord, with no consultation with 'higher' instances.

 

They think they are Satoshi, too, you know!

 

All ten of them, even though I only use index plus middle for typing, and thumbs for some spaces or upper case... but they all insist regardless.

 

Sorry about that! 

 

Cheers,

 

Jeremy



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

0 Likes

Sorry, DaLe,

 

I know very well, but somehow my fingers went off on their own accord, with no consultation with 'higher' instances.

 

They think they are Satoshi, too, you know!

 

All ten of them, even though I only use index plus middle for typing, and thumbs for some spaces or upper case... but they all insist regardless.

 

Sorry about that! 

 

Cheers,

 

Jeremy



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

Message 8 of 10
pmeigneux
in reply to: Dale.Bartlett

pmeigneux
Advocate
Advocate
Thank you Dale..

Philippe Meigneux.
0 Likes

Thank you Dale..

Philippe Meigneux.
Message 9 of 10
Dale.Bartlett
in reply to: pmeigneux

Dale.Bartlett
Collaborator
Collaborator
I suspect the code was originally from Jeremy, but I will accept kudos on his behalf...



______________
Yes, I'm Satoshi.
0 Likes

I suspect the code was originally from Jeremy, but I will accept kudos on his behalf...



______________
Yes, I'm Satoshi.
Message 10 of 10
jeremytammik
in reply to: pmeigneux

jeremytammik
Autodesk
Autodesk

To round off this, here is another code snippet demonstrating an equivalent solution:

 

  FilteredElementCollector fec1 = new FilteredElementCollector(doc);
  fec1.OfClass(typeof(ImportInstance));
  
  Element element = fec1.FirstElement();            
  Element elementType = doc.GetElement(element.GetTypeId());
  
  ExternalFileReference exRefType = null;
  
  try 
  {
    exRefType = elementType.GetExternalFileReference();
  }
  catch (Exception e)
  {
  }
  
  TaskDialog.Show("ExtFileRef", "Type: "
    + ModelPathUtils.ConvertModelPathToUserVisiblePath(
      exRefType.GetPath()));

 

Cheers,

 

Jeremy



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

To round off this, here is another code snippet demonstrating an equivalent solution:

 

  FilteredElementCollector fec1 = new FilteredElementCollector(doc);
  fec1.OfClass(typeof(ImportInstance));
  
  Element element = fec1.FirstElement();            
  Element elementType = doc.GetElement(element.GetTypeId());
  
  ExternalFileReference exRefType = null;
  
  try 
  {
    exRefType = elementType.GetExternalFileReference();
  }
  catch (Exception e)
  {
  }
  
  TaskDialog.Show("ExtFileRef", "Type: "
    + ModelPathUtils.ConvertModelPathToUserVisiblePath(
      exRefType.GetPath()));

 

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 Design & Make Report