Get datalink path from closed drawing C#

Get datalink path from closed drawing C#

klonbeck
Advocate Advocate
1,951 Views
6 Replies
Message 1 of 7

Get datalink path from closed drawing C#

klonbeck
Advocate
Advocate

I am wanting to get the path(s) of all the datalinks in a closed drawing, without opening the drawing in AutoCAD.

 

Since the number of drawings that need to be inspected will be unknown, I dont want to deal with the delay of opening the drawing in AutoCAD since there could be a large number of drawings. 

 

using the DataLinkManager I have been able to see how many datalinks are in a closed drawing, but I have not been able to figure out how to get the path of each datalink.

 

0 Likes
Accepted solutions (2)
1,952 Views
6 Replies
Replies (6)
Message 2 of 7

norman.yuan
Mentor
Mentor

Given the fact that namespace Autodesk.AutoCAD.DatabaseServices in acdbmgd.dll covers the related classes/properties

 

DataLink

DataLinkManager

Database.DataLinkDictionaryId

Database.DataLinkManager

 

I assume you can open a drawing as side database and access these classes/properties for the information you need. But I have not done anything in .NET API with DataLink. Just a thought.

Norman Yuan

Drive CAD With Code

EESignature

0 Likes
Message 3 of 7

klonbeck
Advocate
Advocate

Thank you for the reply!

 

Yes I am able to open a drawing in a side database and read through the database. I have found the datalink members that you listed, but I have not been able to discover how to get the path that the datalink is pointing to.

 

As far as our use of the datalinks we typically use the relative path option instead of the full path option. Not sure if this makes a difference in how I need to get the path of the datalink.

 

0 Likes
Message 4 of 7

norman.yuan
Mentor
Mentor
Accepted solution

Did you notice that DataLink class has a method

 

GetSourceFiles() 

 

I assume you can loop through DataLinkDictionary for each DataLink available in the drawing, and for each DataLink object, use GetSourceFiles() to find out the linked data source file path.

 

Norman Yuan

Drive CAD With Code

EESignature

Message 5 of 7

klonbeck
Advocate
Advocate

I had not noticed the GetSourceFiles().

 

I will check it out.

0 Likes
Message 6 of 7

klonbeck
Advocate
Advocate
Accepted solution

Using your point of looping through the DatalinkDictionary, I have been able to get to a point where I am able to get values that contain the relative path for the datalink and the true path of the datalink.

 

 

using (Transaction Tx = db.TransactionManager.StartTransaction())
{
    ed.WriteMessage("\n---List of datlinks in drawing------------------");
    using (DBDictionary DatalinkDictionary = (DBDictionary)Tx.GetObject(db.DataLinkDictionaryId, OpenMode.ForRead))
    {
        foreach (DBDictionaryEntry DlinkDictEntry in DatalinkDictionary)
        {
            DataLink DataLinkItem = (DataLink)DlinkDictEntry.Value.GetObject(OpenMode.ForRead);
            string RelativePath = DataLinkItem.ConnectionString;
            string TruePath = DataLinkItem.ToolTip;
            ed.WriteMessage("\n---Relative Path---" + RelativePath);
            ed.WriteMessage("\n---True Path---" + TruePath);
        }
    }
    ed.WriteMessage("\n---End of datalink list-------------------------\n");
}

 

The code does not show the creation of the side database since I am only interested in the datalink(s) in the drawing.

 

The value of RelativePath is ".\\PROJECT_FILES\\PANEL_MAPS\\EXTRUDER ENCLOSURE LABELS.xls!Plabel_1!Plabel_1".

The value of TruePath is "Data Link\nPLABEL_1\nC:\\Vault\\Projects\\EXTRUDER\\43mm ENTEK\\Electrical Master Project\\PROJECT_FILES\\PANEL_MAPS\\EXTRUDER ENCLOSURE LABELS.xls\nLink details: Named range: Plabel_1"

 

While ConnectionString and ToolTip are padded with extra data, that extra data has so far been predictable. Striping off the extra data is an easy task so this would be one way I can get the value I want.

 

If I try to use "DataLinkItem.GetSourceFiles(DataLinkGetSourceContext.OrignalPath)" the returned value is "0". Maybe I am misusing the GetSourceFiles() but I was not able to get a file path out of it. Am I using GetSourceFiles() incorrectly?

 

 

0 Likes
Message 7 of 7

klonbeck
Advocate
Advocate
There may be a better way of getting the result that I am looking for, but I am going to accept this as the solution. This gives me a value that I can work with and it will meet the needs of the application I am working on.

Thank you for the help.
0 Likes