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.
选择过滤器列表由成对的以 TypedValues 形式的参数组成。TypedValue 的 第一个参数标识过滤器的类型(例如对象),第二个参数指定要过滤的值(例如圆)。过滤器类型是指定使用哪种过滤器的 DXF 组码。下面列出了一些最常用的过滤器类型。
For a complete list of DXF group codes, see Group Code Value Types in the DXF Reference.
有关 DXF 组码的完整列表,请参见《DXF 参考手册》中的“组码值类型”。
The following code prompts users to select objects to be included in a selection set, and filters out all objects except for circles.
下面的代码提示用户选择要包含在选择集中的对象,并过滤掉除圆之外的所有对象。
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.EditorInput
<CommandMethod("FilterSelectionSet")> _
Public Sub FilterSelectionSet()
'' 获得当前文档的编辑器 Get the current document editor
Dim acDocEd As Editor = Application.DocumentManager.MdiActiveDocument.Editor
'' 创建一个 TypedValue 数组,用于定义过滤条件 Create a TypedValue array to define the filter criteria
Dim acTypValAr(0) As TypedValue
acTypValAr.SetValue(New TypedValue(DxfCode.Start, "CIRCLE"), 0)
'' 赋值过滤条件给 SelectionFilter 对象 Assign the filter criteria to a SelectionFilter object
Dim acSelFtr As SelectionFilter = New SelectionFilter(acTypValAr)
'' 要求在图形区域中选择对象 Request for objects to be selected in the drawing area
Dim acSSPrompt As PromptSelectionResult
acSSPrompt = acDocEd.GetSelection(acSelFtr)
'' 如果提示状态是 OK,对象就被选择了 If the prompt status is OK, objects were selected
If acSSPrompt.Status = PromptStatus.OK Then
Dim acSSet As SelectionSet = acSSPrompt.Value
Application.ShowAlertDialog("Number of objects selected: " & _
acSSet.Count.ToString())
Else
Application.ShowAlertDialog("Number of objects selected: 0")
End If
End Sub
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;
// 创建一个 TypedValue 数组,用于定义过滤条件 Create a TypedValue array to define the filter criteria
TypedValue[] acTypValAr = new TypedValue[1];
acTypValAr.SetValue(new TypedValue((int)DxfCode.Start, "CIRCLE"), 0);
// 赋值过滤条件给 SelectionFilter 对象 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);
// 如果提示状态是 OK,对象就被选择了 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");
}
}