.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to find Layout is empty or not?

3 REPLIES 3
SOLVED
Reply
Message 1 of 4
thenndral
726 Views, 3 Replies

How to find Layout is empty or not?

Hello,

 

Is it possible to distinguish whether a Layout is empty or not?
I need to check this routine in plenty of drawing, so please tell me some easy way to find empty layout.

 

 

Thanks in advance,
thenndral

3 REPLIES 3
Message 2 of 4
Ajilal.Vijayan
in reply to: thenndral

You may need iterate through the BlockTableRecord of each layout to find whether it contains any objects.

 

 

 

Message 3 of 4
_gile
in reply to: Ajilal.Vijayan

Hi,

 

Keep in mind an empty Layout BlockTableRecord anayway contains a Viewport (the layout viewport, cvport = 1).



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 4 of 4
thenndral
in reply to: _gile

Hi,

 

Thanks _gile for an awesome code.

May be this code will helpful for someone.

 

 

            Document doc = AcAp.DocumentManager.MdiActiveDocument;
            Database db = doc.Database;
            Editor ed = doc.Editor;
 
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                var layouts = (DBDictionary)tr.GetObject(db.LayoutDictionaryId, OpenMode.ForRead);
                foreach (var entry in layouts)
                {
                    var layout = (Layout)tr.GetObject(entry.Value, OpenMode.ForRead);
                    var btr = (BlockTableRecord)tr.GetObject(layout.BlockTableRecordId, OpenMode.ForRead);
                    ed.WriteMessage("\n{0} contains {1} ObjectId.", layout.LayoutName, btr.Cast<ObjectId>().Count());
                }
                tr.Commit();
            }

 

 

Thanks again,

thenndral

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost