選択フィルタの中のシンボル名や文字列には、ワイルドカード パターンを含めることができます。
次の表では、AutoCAD が認識できるワイルドカード文字と、それぞれの意味を示します。
|
ワイルド カード文字 |
|
|---|---|
|
文字 |
定義 |
|
# (シャープ記号) |
1 つの数字にマッチします |
|
@ (アット記号) |
1 つのアルファベット文字にマッチします |
|
. (ピリオド) |
1 つの非英数字にマッチします |
|
* (アスタリスク) |
空文字列を含む任意の文字シーケンスにマッチし、検索パターンの先頭、中間、末尾のどこにでも使用できます。 |
|
? (疑問符) |
任意の 1 文字にマッチします |
|
~ (ティルダ) |
パターンの先頭の文字の場合、パターン以外の任意の文字にマッチします |
|
[...] |
囲まれた文字のいずれか 1 文字にマッチします |
|
[~...] |
囲まれた文字以外の 1 文字にマッチします |
|
- (ハイフン) |
角括弧内で使用され、文字の範囲を指定します |
|
, (カンマ) |
2 つのパターンを区切ります |
|
` (逆クォーテーション) |
特殊文字をエスケープします(次の文字を文字どおりに読みます) |
逆クォーテーション(`)をワイルド カードでない文字の前に付けると、逆クォーテーションも文字として扱われます。たとえば、選択セットで名前のないブロック「*U2」を指定するには、「`*U2」という値を指定します。
次の例では、「The」という文字列を含む MText オブジェクトを選択する選択フィルタを定義しています。
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");
}
}