选择筛选器中的符号名称和字符串可以包含通配符模式。 下表标识了 AutoCAD 可识别的通配符,以及每个通配符在字符串上下文中的含义:
使用反引号 (') 表示字符不是通配符,而是按字面意思理解。例如,若要指定在选择集中仅包含名为“*U2”的匿名块,请使用值“'*U2”。 选择文本中出现特定单词的 MText下面的示例定义一个选择筛选器,该筛选器选择包含文本字符串“The”的对象。MText VB.NETImports 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
C#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");
}
}
VBA/ActiveX 代码参考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
相关概念父主题: | ||||||||||||||||||||||||||
|Archiver|CAD开发者社区
( 苏ICP备2022047690号-1 苏公网安备32011402011833)
GMT+8, 2025-10-29 09:45
Powered by Discuz! X3.4
Copyright © 2001-2021, Tencent Cloud.