使用选择集过滤器定义选择集规则
 
 

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 组码。下面列出了一些最常用的过滤器类型。

常用过滤器的 DXF 组码

DXF 码

过滤器类型

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.”

图层名(字符串)

例如 Layer 0

60 (DxfCode.Visibility)

Object Visibility (Integer)

Use 0 = visible, 1 = invisible.

可见性(整数)

使用 0 = 可见,1 = 不可见。

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.

颜色编号(整数)

范围 0 到 256 内的数字索引值。

零表示 BYBLOCK。256 表示 BYLAYER。负值表示图层被关闭。

67

Model/paper space indicator (Integer)

Use 0 or omitted = model space, 1 = paper space.

模型/图纸空间标识符(整数)

使用 0 或省略 = 模型空间,1 = 图纸空间。

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.

下面的代码提示用户选择要包含在选择集中的对象,并过滤掉除圆之外的所有对象。

VB.NET

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

C#

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");
  }
}
VBA/ActiveX 代码参考