While using “Editor.SelectAll” API, you can provide “SelectionFilter” to filter out the unwanted entities. Below code shows a simple example which only gets the Lines and circles from a specified layer only (0, Layer1, Layer2).
[CommandMethod("LayerSelection")]
public void LayerSelection()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
TypedValue[] filterlist = new TypedValue[2];
//select circle and line
filterlist[0] = new TypedValue(0, "CIRCLE,LINE");
//8 = DxfCode.LayerName
filterlist[1] = new TypedValue(8, "0,Layer1,Layer2");
SelectionFilter filter =
new SelectionFilter(filterlist);
PromptSelectionResult selRes = ed.SelectAll(filter);
if (selRes.Status != PromptStatus.OK)
{
ed.WriteMessage(
"nerror in getting the selectAll");
return;
}
ObjectId[] ids = selRes.Value.GetObjectIds();
ed.WriteMessage("No entity found: "
+ ids.Length.ToString() + "n");
}

Leave a Reply to OCODERCancel reply