Count model space entities

Top  Previous  Next

Here you go



      public void CountModelSpaceEntities()


          // get the database and editor of the active document

          var doc = Application.DocumentManager.MdiActiveDocument;

          var db = doc.Database;

          var ed = doc.Editor;


          // start a transaction

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


              // open the model space block table record

              var ms = (BlockTableRecord)tr.GetObject(

                  SymbolUtilityServices.GetBlockModelSpaceId(db), OpenMode.ForRead);


              // iterate through the model space to count all objectIds grouped by their ObjectARX (C++) name

              foreach (var item in ms


                   .ToLookup(id => id.ObjectClass.Name))


                  string sMsg = string.Format("{0} {1}\n",item.Key,item.Count());