When using code like whats posted below (which does not work), how can you get the layer? I have tried serval methods, and none seem to work. I'm so lost. Any/all help appreciated.
public void MyPrintMspace()
{
Database db = HostApplicationServices.WorkingDatabase;
Transaction trans = db.TransactionManager.StartTransaction();
Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
BlockTable bt = (BlockTable)(trans.GetObject(db.BlockTableId, OpenMode.ForRead));
BlockTableRecord btr =(BlockTableRecord)trans.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForRead);
foreach (ObjectId ObjId in btr)
{
DBObject DbObj = trans.GetObject(ObjId, OpenMode.ForRead);
ed.WriteMessage("\n " + DbObj.ToString());
Entity Ent = trans.GetObject(ObjId, OpenMode.ForRead);
ed.WriteMessage("\n Layer: " + Ent.Layer);
}
trans.Commit();
trans.Dispose();
}