Detaching missing external reference files from side database

<?xml encoding=”UTF-8″>By Virupaksha Aithal

Below code shows the procedure to detach the missing external reference files from a side database

[CommandMethod("DetachXref")]
public void detach_xref()
{
Document Doc = Application.DocumentManager.MdiActiveDocument;
Editor ed = Doc.Editor;
string mainDrawingFile = @"C:xrefRectHost.dwg";
using(Database db = new Database(false, false))
{
try
{
db.ReadDwgFile(mainDrawingFile, System.IO.FileShare.ReadWrite, false, "");
}
catch (System.Exception)
{
ed.WriteMessage("nUnable to read the drawingfile.");
return;
}
bool saveRequired = false;
db.ResolveXrefs(true, false);
using (Transaction tr = db.TransactionManager.StartTransaction())
{
XrefGraph xg = db.GetHostDwgXrefGraph(true);
int xrefcount = xg.NumNodes;
for (int j = 0; j < xrefcount; j++)
{
XrefGraphNode xrNode = xg.GetXrefNode(j);
String nodeName = xrNode.Name;
if (xrNode.XrefStatus == XrefStatus.FileNotFound)
{
ObjectId detachid = xrNode.BlockTableRecordId;
db.DetachXref(detachid);
saveRequired = true;
ed.WriteMessage("nDetached successfully");
break;
}
}
tr.Commit();
}
if (saveRequired)
db.SaveAs(mainDrawingFile, DwgVersion.Current);
}
}

Comments

3 responses to “Detaching missing external reference files from side database”

  1. Hi Mr. Virupaksha Aithal, first i’m sorry to post use this link to ask. I’m Jemmy from Indonesia. I have a question, how to save (or export /ex. oraexport) my topology into my oracle spatial using c# from my autocad map 3d 2009. Thanks for helping me.

  2. Hi Jemmy,
    My suggestion is to ask this question on MAP 3d api forum http://forums.autodesk.com/t5/autocad-map-3d-developer/bd-p/84
    I have no knowledge of MAP 3D API.
    Thanks
    Viru

  3. thanks for your suggestion mr. Viru.

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading