Valued Contributor
Posts: 86
Registered: ‎02-28-2012
Message 1 of 3 (136 Views)
Accepted Solution

how to know current drawing is don't have any xref.

136 Views, 2 Replies
08-23-2012 12:00 AM



How to know current drawing is don't have any xref




Valued Mentor
Posts: 266
Registered: ‎11-29-2008
Message 2 of 3 (127 Views)

Re: how to know current drawing is don't have any xref.

08-23-2012 02:41 AM in reply to: RamanSBV

Try here



but long story short :


            Document doc = acadApp.DocumentManager.MdiActiveDocument;

            Database db = doc.Database;

            Editor ed = doc.Editor;

            // Get the xref graph for the current dbase...

            XrefGraph xrefGraph = db.GetHostDwgXrefGraph(true);
            if (xrefGraph == null || xrefGraph.IsEmpty || xrefGraph.NumNodes == 1)
                ed.WriteMessage("\nNo xrefs found.");



class keyThumper<T> : Lazy<T>;      another  Swamper

*Expert Elite*
Posts: 1,569
Registered: ‎10-08-2008
Message 3 of 3 (106 Views)

Re: how to know current drawing is don't have any xref.

08-23-2012 06:10 AM in reply to: RamanSBV

      You may want to loop through BlockTable and check  

     all BlockTableRecord on properties:  

    IsFromExternalReference or IsFromOverlayReference  

    Not tested, just was written in notepad




    public static void testXref()    


         bool whatabout = XrefIncluded();     




    public static bool XrefIncluded()    


          bool include = false;    

         Document doc = Application.DocumentManager.MdiActiveDocument;     

        Database db = doc.Database;     

                   using (Transaction tr = db.TransactionManager.StartTransaction())     


          BlockTable bt = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;    

          foreach (ObjectId id in bt)          


             BlockTableRecord btr = tr.GetObject(id, OpenMode.ForRead, false) as BlockTableRecord;    

             // check if Xref        

         if (btr.IsFromExternalReference || btr.IsFromOverlayReference)        


     include= true;   






           return include;    




You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community