// © Andrey Bushman, 2014
/// <summary>
/// Sample: get all ids of entities which are located on some layer
/// (0 for example).
/// </summary>
[Rt.CommandMethod("Test", Rt.CommandFlags.Modal)]
public void Command_Test() {
Ap.Document doc = cad.DocumentManager.MdiActiveDocument;
if (null == doc) {
return;
}
Db.Database db = doc.Database;
Ed.Editor ed = doc.Editor;
Rt.RXClass entityRXType = Rt.RXClass.GetClass(typeof(Db.Entity));
using (doc.LockDocument()) {
// Ids of all entities
// Code of the GetDBObjectIds method look here:
// http://adn-cis.org/forum/index.php?topic=1060.msg5315#msg5315
Db.ObjectId[] entityIds = db.GetDBObjectIds(n => !n.IsErased &&
!n.IsEffectivelyErased && n.ObjectClass.IsDerivedFrom(
entityRXType));
// target layer
Db.ObjectId layerId = db.LayerZero; // for example
// result what you need
List<Db.ObjectId> resultIds = new List<Db.ObjectId>();
using (Db.Transaction tr = db.TransactionManager
.StartTransaction()) {
foreach (Db.ObjectId id in entityIds) {
Db.Entity entity = tr.GetObject(id, Db.OpenMode
.ForRead, false, true) as Db.Entity;
if (entity.LayerId == layerId) {
resultIds.Add(id);
}
}
tr.Commit();
}
}
}