.NET

.NET

Reply
Valued Contributor
88 Posts
0 Kudos
Registered: ‎02-28-2012
Post 1 of 3
Accepted Solution

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

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

Hi,

 

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

 

Regards,

Raman

Try here

http://www.theswamp.org/index.php?topic=22884.msg275290#msg275290

 

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.");
return;
}

 

      You may want to loop through BlockTable and check  

     all BlockTableRecord on properties:  

    IsFromExternalReference or IsFromOverlayReference  

    Not tested, just was written in notepad

 

 

 [CommandMethod("xrf")]
public static void testXref()
{
bool whatabout = XrefIncluded();
Autodesk.AutoCAD.ApplicationServices.Application.ShowAlertDialog(string.Format("Xref?\t{0}",
whatabout));
}
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;
break;
}
}
tr.Commit();
}
return include;
}

 

Valued Mentor
278 Posts
22 Kudos
Registered: ‎11-29-2008
Post 2 of 3

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

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

Try here

http://www.theswamp.org/index.php?topic=22884.msg275290#msg275290

 

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.");
                return; 
            }

 

//-------------------------------------------------------

Everything will work just as you expect it to, unless your expectations are incorrect.

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

*Expert Elite*
1,569 Posts
171 Kudos
Registered: ‎10-08-2008
Post 3 of 3

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

 

 

        [CommandMethod("xrf")]     

    public static void testXref()    

     {    

         bool whatabout = XrefIncluded();     

        Autodesk.AutoCAD.ApplicationServices.Application.ShowAlertDialog(string.Format("Xref?\t{0}", 

whatabout));       

  }     

    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;   

                  break;     

            }   

           }     

            tr.Commit();  

           }  

           return include;    

     }

 

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Are you interested in helping shape the future of the Autodesk Community? To participate in this brief usability study, please click here. Your time and input is greatly appreciated!