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 能够识别的通配符以及每个通配符在上下文字符串中的含义:
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”。
The following example defines a selection filter that selects MText objects that contain the text string of “The”.
以下代码将选择条件定义为选择所有文字字符串中出现“The”的多行文字。
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
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");
}
}