1

Is there any way to extract all the external links files that have a CAD file?

Any library in c# or another programming language? Thanks in advance.

karrtojal
  • 796
  • 7
  • 16

1 Answers1

1

Ad hoc sample would be:

ObjectIdCollection XRefs = new ObjectIdCollection();

Database db = HostApplicationServices.WorkingDatabase;
using (Transaction tr = db.TransactionManager.StartTransaction())
{
    BlockTable blocks = tr.GetObject(db.BlockTableId, OpenMode.ForRead, false) as BlockTable;
    foreach (ObjectId blockId in blocks)
    {
        BlockTableRecord bx = tr.GetObject(blockId, OpenMode.ForRead, false) as BlockTableRecord;
        if (bx.IsFromExternalReference)
        {
            ObjectIdCollection references = bx.GetBlockReferenceIds(true, true);
            foreach (ObjectId ref in references)
            XRefs.Add (ref)
        }
    }
    tr.Dispose()
}
CAD Developer
  • 1,532
  • 2
  • 21
  • 27
  • Hi, to compile these code, I guess that I have to install in the c# project with nuget the AutoCAD.NET. But my project is in 4.5 version. I have to find what version match. Where is the original CAD file opened? – karrtojal Jan 30 '20 at 15:33
  • 1
    This code can be compiled in project based on ObjectARX. so the output is dll file which can be loaded to AutoCAD by _netload command in AutoCAD. nuget package is not necessary. My project is based on .Net Framework 4. with referenced ARX sdk libraries. Drawing is opened in AutoCAD, to be honest in my case it's ZWCAD, but this should be no difference. – CAD Developer Jan 31 '20 at 07:05