A selection filter can contain filtering criteria for more than just one property or object. You define the total number of conditions to filter on by declaring an array containing enough elements to represent each of the filter criterion.
一个选择集过滤器可以包含适用于多个属性或对象的过滤条件。声明的数组应该包含足够多的元素来表示每个条件。
The following example specifies two criterion to filter selected objects by: the object must be a circle and it must reside on layer 0.
以下示例指定了两个选择对象的过滤条件:对象必须是圆,并且必须在图层 0 上。
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.EditorInput
<CommandMethod("FilterBlueCircleOnLayer0")> _
Public Sub FilterBlueCircleOnLayer0()
'' 获得当前文档的编辑器 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(2) As TypedValue
acTypValAr.SetValue(New TypedValue(DxfCode.Color, 5), 0)
acTypValAr.SetValue(New TypedValue(DxfCode.Start, "CIRCLE"), 1)
acTypValAr.SetValue(New TypedValue(DxfCode.LayerName, "0"), 2)
'' 赋值过滤条件给 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("FilterBlueCircleOnLayer0")]
public static void FilterBlueCircleOnLayer0()
{
// 获得当前文档的编辑器 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[3];
acTypValAr.SetValue(new TypedValue((int)DxfCode.Color, 5), 0);
acTypValAr.SetValue(new TypedValue((int)DxfCode.Start, "CIRCLE"), 1);
acTypValAr.SetValue(new TypedValue((int)DxfCode.LayerName, "0"), 2);
// 赋值过滤条件给 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");
}
}