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:
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”.
Select MText where a specific word appears in the text
The following example defines a selection filter that selects MText objects that contain the text string of “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
'' 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)
'' 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)
'' 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;
// 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);
// 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);
// 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");
}
}