I am trying to create a utility for AutoCAD to bind all xrefs. I have ran into trouble with E-transmit when an xref is unloaded. I have found that you can do a switch for XREFSTATUS and am able to get all resolved xref's. It seems that when I run the code it says they are bound but when I open xref manager they are not.
Is there something similar to editing attributes where I need to open the xref for editing and then close it? I have seen an xrefeditenable command
Below is my current code setup. I plan on making a collection for each XREFSTATUS and working with it accordingly.
Code:[CommandMethod("Bindem")] public void bindXref() { Document doc = acad.DocumentManager.MdiActiveDocument; Editor ed = doc.Editor; Database db = doc.Database; Transaction tr = doc.TransactionManager.StartTransaction(); try { using (tr) { ObjectIdCollection btrCol = new ObjectIdCollection(); XrefGraph xrgraph = doc.Database.GetHostDwgXrefGraph(false); // look at all Nodes in the XrefGraph. Skip 0 node since it is the drawing itself. for (int i = 1; i < (xrgraph.NumNodes - 1); i++) { XrefGraphNode xrNode = xrgraph.GetXrefNode(i); BlockTableRecord btr = (BlockTableRecord)tr.GetObject (xrNode.BlockTableRecordId, OpenMode.ForWrite); switch (xrNode.XrefStatus) { //if it is a resolved xref, then add to collection to be bound case Autodesk.AutoCAD.DatabaseServices.XrefStatus.Resolved: btrCol.Add(btr.ObjectId); ed.WriteMessage("\n Xref added: " + btr.Name); break; case Autodesk.AutoCAD.DatabaseServices.XrefStatus.Unloaded: break; case Autodesk.AutoCAD.DatabaseServices.XrefStatus.FileNotFound: break; case Autodesk.AutoCAD.DatabaseServices.XrefStatus.NotAnXref: break; case Autodesk.AutoCAD.DatabaseServices.XrefStatus.Unreferenced: break; } } ed.WriteMessage("\nTrying to bind"); try { //if there are xref id's in btrCol then attempt to bind each one if (btrCol.Count > 0) { foreach (ObjectId id in btrCol) { db.BindXrefs(btrCol, true); ed.WriteMessage("\nBound"); } } } catch (Autodesk.AutoCAD.Runtime.Exception ee) { ed.WriteMessage("\n Could Not Bind!" + ee); } } } catch (Autodesk.AutoCAD.Runtime.Exception ee) { ed.WriteMessage("\nFailed!" + ee); } }


Reply With Quote