Selection filters are composed of pairs of arguments in the form of TypedValues. The first argument of a TypedValue identifies the type of filter (for example, an object), and the second argument specifies the value you are filtering on (for example, circles). The filter type is a DXF group code that specifies which filter to use. A few of the most common filter types are listed here.
|
DXF codes for common filters |
|
|---|---|
|
DXF code |
Filter type |
|
0 (or DxfCode.Start) |
Object Type (String) Such as “Line,” “Circle,” “Arc,” and so forth. |
|
2 (or DxfCode.BlockName) |
Block Name (String) The block name of an insert reference. |
|
8 or (DxfCode.LayerName) |
Layer Name (String) Such as “Layer 0.” |
|
60 (DxfCode.Visibility) |
Object Visibility (Integer) Use 0 = visible, 1 = invisible. |
|
62 (or DxfCode.Color) |
Color Number (Integer) Numeric index values ranging from 0 to 256. Zero indicates BYBLOCK. 256 indicates BYLAYER. A negative value indicates that the layer is turned off. |
|
67 |
Model/paper space indicator (Integer) Use 0 or omitted = model space, 1 = paper space. |
The following example prompts users to select objects to be included in a selection set, and filters out all objects except for circles.
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
[CommandMethod("FilterSelectionSet")]
public static void FilterSelectionSet()
{
// Get the current document editor
Editor acDocEd = Application.DocumentManager.MdiActiveDocument.Editor;
// Create a TypedValue array to define the filter criteria
TypedValue[] acTypValAr = new TypedValue[1];
acTypValAr.SetValue(new TypedValue((int)DxfCode.Start, "CIRCLE"), 0);
// Assign the filter criteria to a SelectionFilter object
SelectionFilter acSelFtr = new SelectionFilter(acTypValAr);
// Request for objects to be selected in the drawing area
PromptSelectionResult acSSPrompt;
acSSPrompt = acDocEd.GetSelection(acSelFtr);
// If the prompt status is OK, objects were selected
if (acSSPrompt.Status == PromptStatus.OK)
{
SelectionSet acSSet = acSSPrompt.Value;
Application.ShowAlertDialog("Number of objects selected: " +
acSSet.Count.ToString());
}
else
{
Application.ShowAlertDialog("Number of objects selected: 0");
}
}