Another example. I think you'll see the potential of this one?
[CommandMethod("NXL")]
static public void NestedXrefsCommand()
{
// Get a pointer to the active document...
Document pCurDoc = pAcadApp.DocumentManager.MdiActiveDocument;
// From the active document, get a pointer to the doc's dbase...
Database pCurDb = pCurDoc.Database;
// Get a pointer to the editor...
Editor pEd = pCurDoc.Editor;
// Get the xref graph for the current dbase...
XrefGraph pXrefGraph = pCurDb.GetHostDwgXrefGraph(true);
if (pXrefGraph.IsEmpty || pXrefGraph.NumNodes == 1)
{
pEd.WriteMessage("\nNo xrefs found.");
return; // No xrefs...
}
using (Transaction pTr = pCurDoc.TransactionManager.StartTransaction())
{
BlockTable pBlkTbl = (BlockTable)pTr.GetObject(pCurDb.BlockTableId, OpenMode.ForRead);
for (int i = 0; i < pXrefGraph.NumNodes; i++)
{
XrefGraphNode pXrefGraphNode = (XrefGraphNode)pXrefGraph.GetXrefNode(i);
// Is it the root node, which is the current drawing?
// If it IS, then the number of incoming nodes will be 0...
if (pXrefGraphNode.NumIn == 0)
continue;
// Continue if it's truly nested...
if (pXrefGraphNode.IsNested)
continue;
// Number of incoming nodes should only be 1 (the current drawing itself)
// for TRUE top level non-nested xref...
if (pXrefGraphNode.NumIn > 1)
continue;
pEd.WriteMessage("\nXref name: " + pXrefGraphNode.Name);
pEd.WriteMessage("\nNested status: " + pXrefGraphNode.IsNested.ToString());
pEd.WriteMessage("\nIncoming nodes: " + pXrefGraphNode.NumIn.ToString());
pEd.WriteMessage("\nOutgoing nodes: " + pXrefGraphNode.NumOut.ToString());
}//for
// Commit the transaction on the dbase...
pTr.Commit();
}//using
}
Cheers,