using (doc.LockDocument()) {
using (Db.Transaction tr = db.TransactionManager.StartTransaction()) {
Db.BlockTable bt = tr.GetObject(db.BlockTableId, Db.OpenMode.ForRead)
as Db.BlockTable;
if (!bt.Has(blockName)) return null;
Db.ObjectId defId = bt[blockName];
Db.BlockTableRecord btr = tr.GetObject(defId, Db.OpenMode.ForRead)
as Db.BlockTableRecord;
foreach (Db.ObjectId id in btr.GetBlockReferenceIds(false, false)) {
result.Add(id);
Db.BlockReference br = tr.GetObject(id, Db.OpenMode.ForWrite) as Db.BlockReference;
}
#if DEBUG
ed.WriteMessage("Количество вхождений блока {0}: {1}\n", blockName, result.Count);
#endif
if (btr.IsDynamicBlock) {
#if DEBUG
ed.WriteMessage("Анонимные блоки:\n");
#endif
foreach (Db.ObjectId id in btr.GetAnonymousBlockIds()) {
Db.BlockTableRecord btr2 = tr.GetObject(id, Db.OpenMode.ForRead)
as Db.BlockTableRecord;
foreach (Db.ObjectId id2 in btr2.GetBlockReferenceIds(false, false)) {
result.Add(id2);
}
#if DEBUG
ed.WriteMessage("Количество вхождений блока {0}: {1}\n", btr2.Name,
btr2.GetBlockReferenceIds(false, false).Count);
#endif
}
#if DEBUG
ed.WriteMessage("Общее количество вхождений: {0}\n", result.Count);
#endif
}
tr.Commit();
}