
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello Coders,
I am new here, I am a bigginer.
Here is my issue.
I wanted to detach xrefs that having status File Not found from multiple drawings (fodlers and sub folders)
without opening the drawing file.
- I am able to get all the dwg files from folders and subfodlers.
- am able to find the xrefs that are working and the ones that arent
I am not able to detach the xrefs that are having the status FileNotfound.
I dont know how to get the objectIds of those xrefs. I tried several ways..please help me.
===================================================================================
Here is my code:
=============
[CommandMethod("Dref")]
public void detach_xref()
{
//get the document
Document Doc = Application.DocumentManager.MdiActiveDocument;
Editor ed = Doc.Editor;
// Ask the user to select a folder
PromptResult res = ed.GetString("\nEnter the path of the folder: ");
string[] filepaths = Directory.GetFiles(res.StringResult, "*.dwg", SearchOption.AllDirectories);
int filecount = filepaths.Length;
ed.WriteMessage("\nScanning " + filecount + " files");
for (int i = 0; i < filecount; i++)
{
ed.WriteMessage("\n File Name : " + filepaths[i]);
//create a database and try to load the file
Database db = new Database(false, true);
using (db)
{
try
{
db.ReadDwgFile(filepaths[i], System.IO.FileShare.Read, false, "");
}
catch (System.Exception)
{
ed.WriteMessage("\nUnable to read the drawingfile.");
return;
}
db.ResolveXrefs(true, false);
XrefGraph xg = db.GetHostDwgXrefGraph(true);
int xrefcount = xg.NumNodes - 1;
if(xrefcount > 0)
{
using (Transaction tr = db.TransactionManager.StartTransaction())
{
ObjectIdCollection btcoll = new ObjectIdCollection();
for (int j = 1; i < xrefcount; i++)
{
XrefGraphNode xrNode = xg.GetXrefNode(j);
BlockTableRecord btr = (BlockTableRecord)tr.GetObject(xrNode.BlockTableRecordId, OpenMode.ForWrite);
if (xrNode.XrefStatus == XrefStatus.FileNotFound)
{
foreach (ObjectId id in btr)
{
db.DetachXref(id);
ed.WriteMessage("\nDetached successfully");
}
}
}
//transaction
tr.Commit();
}
}
}
}
}
Solved! Go to Solution.