在选择器过滤器条件中使用通配符
 
 

Symbol names and strings in selection filters can include wild-card patterns.

过滤器列表中的符号名称和字符串可以包含通配符模式。

The following table identifies the wild-card characters recognized by AutoCAD, and what each means in the context of a string:

下表显示了 AutoCAD 能够识别的通配符以及每个通配符在上下文字符串中的含义:

Wild-card characters

通配符

Character

字符

Definition

说明

#?(pound 磅值符号)

Matches any single numeric digit

匹配任意一个数字

@?(at 在符号)

Matches any single alphabetic character

匹配任意一个字母

.?(period 句点)

Matches any single non-alphanumeric character

匹配任意一个非字母数字的字符

*?(asterisk 星号)

Matches any character sequence, including an empty one, and it can be used anywhere in the search pattern: at the beginning, middle, or end

匹配任何字符顺序,包括空字符,可用于搜索模式中的任何位置:在开头、在中间或在结尾

??(question mark 问号)

Matches any single character

匹配任意一个字符

~?(tilde 波浪号)

If it is the first character in the pattern, it matches anything except the pattern

如果它是模式中的的第一个字符,则匹配除此模式以外的任意内容

[...]

Matches any one of the characters enclosed

匹配方括号中的任意一个字符

[~...]

Matches any single character not enclosed

匹配不在方括号中的任意一个字符

-?(hyphen 连字符)

Used inside brackets to specify a range for a single character

用在方括号中,指定一个字符的取值范围

,?(comma 逗号)

Separates two patterns

分隔两个模式

`?(reverse quote 反引号)

Escapes special characters (reads next character literally)

避开特殊的字符(直接读取下一个字符)

Use a reverse quote (`) to indicate that a character is not a wildcard, but is to be taken literally. For example, to specify that only an anonymous block named “*U2” be included in the selection set, use the value“`*U2”.

使用单引号 (`) 表示下一个字符不是通配符,而是普通字符。例如,要指定仅将命名为“*U2”的匿名块包含在选择集中,请使用“`*U2”。

选择包含指定词语的 Mtext

The following example defines a selection filter that selects MText objects that contain the text string of “The”.

以下代码将选择条件定义为选择所有文字字符串中出现“The”的多行文字。

VB.NET

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