CAD开发者社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

ObjectARX 开发指南

在选择集筛选条件中使用通配符模式 (.NET)

2023-1-1 14:20| 发布者: admin| 查看: 376| 评论: 0|来自: AutoCAD

选择过滤器中的符号名称和字符串可以包含通配符模式。

下表标识了 AutoCAD 识别的通配符,以及每个通配符在字符串上下文中的含义:

通配符

字符

定义

#(磅)

匹配任何单个数字

@(在)

匹配任何单个字母字符

.(期间)

匹配任何单个非字母数字字符

*(星号)

匹配任何字符序列,包括空字符序列,并且可以在搜索模式中的任何位置使用:开头、中间或结尾

?(问号)

匹配任何单个字符

~(波浪号)

如果它是模式中的第一个字符,则它匹配除模式之外的任何字符

[...]

匹配包含的任何一个字符

[~...]

匹配未括起来的任何单个字符

- (连字符)

在方括号内用于指定单个字符的范围

,(逗号)

分隔两种模式

`(反向引用)

转义特殊字符(按字面意思读取下一个字符)

使用反引号 (') 表示字符不是通配符,而是按字面意思理解。例如,要指定选择集中仅包含名为“*U2”的匿名块,请使用值“'*U2”。

选择文本中出现特定单词的 MText

下面的示例定义一个选择筛选器,该筛选器选择包含文本字符串“The”的对象。MText

VB.NET

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

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

路过

雷人

握手

鲜花

鸡蛋

最新评论

QQ|Archiver|CAD开发者社区 ( 苏ICP备2022047690号-1 )

GMT+8, 2024-5-19 12:22

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

返回顶部