Lets say you are changing all entities in block definitions to be on layer 0 and by layer
and you do something like
[CommandMethod("BlkDefsToByLayerAndLayerZero")]
public void BlkDefsToByLayerAndLayerZero()
{
using (Transaction trx = Db.TransactionManager.StartTransaction())
{
BlockTable bt = (BlockTable)trx.GetObject(Db.BlockTableId, OpenMode.ForRead);
foreach (ObjectId btrId in bt)
{
BlockTableRecord btr = (BlockTableRecord)trx.GetObject(btrId, OpenMode.ForRead);
if (!btr.IsLayout)
{
foreach (ObjectId entId in btr)
{
Entity ent = (Entity)trx.GetObject(entId, OpenMode.ForRead, false, true);
if (ent.LayerId != Db.LayerZero)
{
ent.UpgradeOpen();
ent.LayerId = Db.LayerZero;
}
if (ent.ColorIndex != 256)
{
ent.UpgradeOpen();
ent.ColorIndex = 256;
}
}
}
}
trx.Commit();
}
}
This will still fail on entities with locked layers
What is normal procedure or better
1. To open all entities ForWrite
2. Something like
foreach (ObjectId entId in modelBtr)
{
Entity ent = (Entity)trx.GetObject(entId, OpenMode.ForRead, false, true);
if (ent.ColorIndex != 256)
{
ent = (Entity)trx.GetObject(entId, OpenMode.ForWrite, false, true);
ent.ColorIndex = 256;
}
}
I would not imagine unlocking the layer storing the id and locking it back would be more efficient than opening all objects, or it might be depending on the drawing.
So what would be the best method to use when you have no idea if the drawing will have one layer that is locked with 10,000 block definitions, or 10,000 locked layers with 10 block definitions, etc.....?