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