Maybe my english isn't so good, but I think I clearly understood what you want to do.
If my C# is better than my English, here's a little sample to change the color of all entities in model space. Maybe you'd have some issues with MText which color is overwriten or with dimension and tables (which inherits from BlockReference).
private void ChangeEntitesColorInModelSpace(short colorIndex)
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
using (doc.LockDocument())
using (Transaction tr = db.TransactionManager.StartTransaction())
{
// Set the color of all entities within block definition to ByBlock
BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead);
foreach (ObjectId btrId in bt)
{
BlockTableRecord btr = (BlockTableRecord)tr.GetObject(btrId, OpenMode.ForRead);
if (!btr.IsLayout)
{
foreach (ObjectId id in btr)
{
Entity ent = (Entity)tr.GetObject(id, OpenMode.ForWrite);
ent.ColorIndex = 0;
}
}
}
// Set the color of all entities within model space to the specified color
BlockTableRecord modelSpace =
(BlockTableRecord)tr.GetObject(SymbolUtilityServices.GetBlockModelSpaceId(db), OpenMode.ForRead);
foreach (ObjectId id in modelSpace)
{
Entity ent = (Entity)tr.GetObject(id, OpenMode.ForWrite);
ent.ColorIndex = colorIndex;
// Sychronize attributes
if (ent is BlockReference)
{
BlockReference br = (BlockReference)ent;
foreach (ObjectId attId in br.AttributeCollection)
{
AttributeReference att = (AttributeReference)tr.GetObject(attId, OpenMode.ForWrite);
att.ColorIndex = 0;
}
}
}
tr.Commit();
}
}
If I still misundertand you, here's another snippet to change the selected attribute references color:
[CommandMethod("AttColor", CommandFlags.Modal)]
public void ChangeAttributeColor()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
RXClass rxc = RXClass.GetClass(typeof(AttributeReference));
using (Transaction tr = db.TransactionManager.StartTransaction())
{
while (true)
{
PromptNestedEntityResult res = ed.GetNestedEntity("\nSelect an attribute: ");
if (res.Status != PromptStatus.OK)
break;
if (res.ObjectId.ObjectClass != rxc)
{
ed.WriteMessage("only an attribute !");
continue;
}
AttributeReference att = (AttributeReference)tr.GetObject(res.ObjectId, OpenMode.ForWrite);
att.ColorIndex = 1;
db.TransactionManager.QueueForGraphicsFlush();
}
tr.Commit();
}
}