添加复杂的过滤器列表条件
 
 

When you specify multiple selection criteria, AutoCAD assumes the selected object must meet each criterion. You can qualify your criteria in other ways. For numeric items, you can specify relational operations (for example, the radius of a circle must be greater than or equal to 5.0). And for all items, you can specify logical operations (for example, Text or MText).

如果指定多个选择条件,AutoCAD 将假设选定对象必须符合所有条件。但用户可以按照其他方式来指定条件。对于数字项,用户可以指定关系运算(例如,圆的半径必须大于或等于 5.0);对于所有项,用户可以指定逻辑运算(例如 Text 或 Mtext)。

Use a -4 DXF code or the constant DxfCode.Operator to indicate a relational operator in a selection filter. The operator is expressed as a string. The allowable relational operators are shown in the following table.

使用 -4 DXF 组码或 DxfCode.Operator 常量来指示过滤器中的关系运算符。以字符串的形式来指定运算符。下表显示了可以使用的关系运算符:

Relational operators for selection set filter lists

选择集过滤器列表的关系运算符

Operator

运算符

Description

说明

"*"

Anything goes (always true)

任何情况(总为真)

"="

Equals

等于

"!="

Not equal to

不等于

"/="

Not equal to

不等于

"<>"

Not equal to

不等于

"<"

Less than

小于

"<="

Less than or equal to

小于或等于

">"

Greater than

大于

">="

Greater than or equal to

大于或等于

"&"

Bitwise AND (integer groups only)

按位 AND(仅限于整数组)

"&="

Bitwise masked equals (integer groups only)

按位屏蔽相等(仅限于整数组)

Logical operators in a selection filter are also indicated by a -4 group code or the constant DxfCode.Operator, and the operator is a string, but the operators must be paired. The opening operator is preceded by a less-than symbol (<), and the closing operator is followed by a greater-than symbol (>). The following table lists the logical operators allowed in selection set filtering.

过滤器列表中的逻辑运算符也由 -4 组代码或 DxfCode.Operator 常量表示,运算符为字符串,但必须组对。运算符以小于号开始 (<),以大于号结束 (>)。下表列出了可以在选择集过滤中使用的逻辑运算符。

Logical grouping operators for selection set filter lists

选择集过滤器列表的逻辑编组运算符

Starting

operator

开始 运算符

Encloses

包含的内容

Ending

operator

结束 运算符

"<AND"

One or more operands

一个或多个运算对象

"AND>"

"<OR"

One or more operands

一个或多个运算对象

"OR>"

"<XOR"

Two operands

两个运算对象

"XOR>"

"<NOT"

One operand

一个运算对象

"NOT>"

选择半径大于或等于 5.0 的圆

The following example selects circles whose radius is greater than or equal to 5.0.

以下示例指定选择半径大于或等于 5.0 的圆:

VB.NET

Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.EditorInput
 
<CommandMethod("FilterRelational")> _
Public Sub FilterRelational()
  '' 获得当前文档的编辑器     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.Start, "CIRCLE"), 0)
  acTypValAr.SetValue(New TypedValue(DxfCode.Operator, ">="), 1)
  acTypValAr.SetValue(New TypedValue(40, 5), 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

C#

using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
 
[CommandMethod("FilterRelational")]
public static void FilterRelational()
{
  // 获得当前文档的编辑器     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.Start, "CIRCLE"), 0);
  acTypValAr.SetValue(new TypedValue((int)DxfCode.Operator, ">="), 1);
  acTypValAr.SetValue(new TypedValue(40, 5), 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");
  }
}
VBA/ActiveX 代码参考

选择 Text 或 Mtext

The following example specifies that either Text or MText objects can be selected.

下例指定选择 Text 或 Mtext 对象:

VB.NET

Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.EditorInput
 
<CommandMethod("FilterForText")> _
Public Sub FilterForText()
  '' 获得当前文档的编辑器     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(3) As TypedValue
  acTypValAr.SetValue(New TypedValue(DxfCode.Operator, "<or"), 0)
  acTypValAr.SetValue(New TypedValue(DxfCode.Start, "TEXT"), 1)
  acTypValAr.SetValue(New TypedValue(DxfCode.Start, "MTEXT"), 2)
  acTypValAr.SetValue(New TypedValue(DxfCode.Operator, "or>"), 3)
 
  '' 赋值过滤条件给 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("FilterForText")]
public static void FilterForText()
{
  // 获得当前文档的编辑器     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[4];
  acTypValAr.SetValue(new TypedValue((int)DxfCode.Operator, "<or"), 0);
  acTypValAr.SetValue(new TypedValue((int)DxfCode.Start, "TEXT"), 1);
  acTypValAr.SetValue(new TypedValue((int)DxfCode.Start, "MTEXT"), 2);
  acTypValAr.SetValue(new TypedValue((int)DxfCode.Operator, "or>"), 3);
 
  // 赋值过滤条件给 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 代码参考