By Virupaksha Aithal
API “Database.BindXrefs” can be used to bind the resolved external references. Below code shows the sample code to use “BindXrefs” API.
[CommandMethod("BX")]
public void BindXrefs()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
ObjectIdCollection xrefCollection = new ObjectIdCollection();
using (XrefGraph xg = db.GetHostDwgXrefGraph(false))
{
int numOfNodes = xg.NumNodes;
for (int cnt = 0; cnt < xg.NumNodes; cnt++)
{
XrefGraphNode xNode = xg.GetXrefNode(cnt)
as XrefGraphNode;
if (!xNode.Database.Filename.Equals(db.Filename))
{
if (xNode.XrefStatus == XrefStatus.Resolved)
{
xrefCollection.Add(xNode.BlockTableRecordId);
}
}
}
}
if(xrefCollection.Count != 0)
db.BindXrefs(xrefCollection, true);
}

Leave a Reply