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