/// <summary>
/// 按色选择
/// </summary>
public void SelectionColor()
{
// 1) Database Get, Document, Editor.
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
SetFocus(doc.Window.Handle);
using (DocumentLock docLock = doc.LockDocument())
{
// 2) Using Transaction
using (Transaction trans = db.TransactionManager.StartTransaction())
{
PromptEntityResult per = ed.GetEntity("请选择对象颜色");
if (per.Status == PromptStatus.OK)
{
Entity ent = trans.GetObject(per.ObjectId, OpenMode.ForRead) as Entity;
LayerTableRecord ltr = (LayerTableRecord)(ent.LayerId).GetObject(OpenMode.ForWrite);
var dbDBEntity = db.GetEntsInModelSpace();
var objs = (from t in dbDBEntity
where (t.EntityColor.ColorIndex.Equals(ent.EntityColor.ColorIndex)) && (((LayerTableRecord)(t.LayerId).GetObject(OpenMode.ForWrite)).Color.ColorIndex.Equals(ltr.Color.ColorIndex))
select t);
//System.Windows.Forms.MessageBox.Show(ent.Layer + "\n" + objs.Count().ToString());
//设置图层的颜色
//ed.WriteMessage("\n\n块表记录颜色" + ltr.Color.ColorIndex+"\n");
if (objs != null)
{
ed.SetImpliedSelection(objs.Select(en => en.ObjectId).ToArray());
}
ed.WriteMessage("\n\n" + ent.EntityColor.ColorIndex + " -----> 共计" + objs.Count().ToString() + "个\n");
}
trans.Commit();
}
}
//MainUI.Instance.Visibility = System.Windows.Visibility.Visible;
}