CAD开发者社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

ObjectARX 开发指南

增加筛选器列表条件的复杂性 (.NET)

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

指定多个选择条件时,AutoCAD 假定所选对象必须满足每个条件。您可以通过其他方式限定您的标准。对于数值项目,可以指定关系运算(例如,圆的半径必须大于或等于5.0)。对于所有项目,您可以指定逻辑操作(例如,或)。TextMText

使用 -4 DXF 代码或常量来指示选择过滤器中的关系运算符。运算符表示为字符串。下表显示了允许的关系运算符。DxfCode.Operator

选择集过滤器列表的关系运算符

算子

描述

"*"

一切顺利(总是正确的)

"="

等于

"!="

不等于

"/="

不等于

"<>"

不等于

"<"

小于

"<="

小于或等于

">"

大于

">="

大于或等于

"&"

按位 AND(仅限整数组)

"&="

按位屏蔽等于(仅限整数组)

选择过滤器中的逻辑运算符也由 -4 组码或常量指示,运算符是字符串,但运算符必须配对。开盘运算符前面是小于号 (<),收盘运算符后跟大于号 (>)。下表列出了选择集过滤中允许的逻辑运算符。DxfCode.Operator

选择集过滤器列表的逻辑分组运算符

启动运算符

包围

结束运算符

"<AND"

一个或多个操作数

"AND>"

"<OR"

一个或多个操作数

"OR>"

"<XOR"

两个操作数

"XOR>"

"<NOT"

一个操作数

"NOT>"

选择半径大于或等于 5.0 的圆

下面的示例选择半径大于或等于 5.0 的圆。

VB.NET

Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.EditorInput
 
<CommandMethod("FilterRelational")> _
Public Sub FilterRelational()
    '' Get the current document editor
    Dim acDocEd As Editor = Application.DocumentManager.MdiActiveDocument.Editor

    '' Create a TypedValue array to define the filter criteria
    Dim acTypValAr(2) As TypedValue
    acTypValAr.SetValue(New TypedValue(DxfCode.Start, "CIRCLE"), 0)
    acTypValAr.SetValue(New TypedValue(DxfCode.Operator, ">="), 1)
    acTypValAr.SetValue(New TypedValue(40, 5), 2)

    '' 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("FilterRelational")]
public static void FilterRelational()
{
    // Get the current document editor
    Editor acDocEd = Application.DocumentManager.MdiActiveDocument.Editor;

    // Create a TypedValue array to define the filter criteria
    TypedValue[] acTypValAr = new TypedValue[3];
    acTypValAr.SetValue(new TypedValue((int)DxfCode.Start, "CIRCLE"), 0);
    acTypValAr.SetValue(new TypedValue((int)DxfCode.Operator, ">="), 1);
    acTypValAr.SetValue(new TypedValue(40, 5), 2);

    // 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 Code Reference

Sub FilterRelational()
    Dim sset As AcadSelectionSet
    Dim FilterType(2) As Integer
    Dim FilterData(2) As Variant
    Set sset = ThisDrawing.SelectionSets.Add("SS1")
    FilterType(0) = 0: FilterData(0) = "Circle"
    FilterType(1) = -4: FilterData(1) = ">="
    FilterType(2) = 40: FilterData(2) = 5#
 
    sset.SelectOnScreen FilterType, FilterData
 
    MsgBox "Number of objects selected: " & sset.Count
 
    ' Remove the selection set at the end
    sset.Delete
End Sub

Select either Text or MText

The following example specifies that either or objects can be selected. TextMText

VB.NET

Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.EditorInput
 
<CommandMethod("FilterForText")> _
Public Sub FilterForText()
    '' Get the current document editor
    Dim acDocEd As Editor = Application.DocumentManager.MdiActiveDocument.Editor

    '' Create a TypedValue array to define the filter criteria
    Dim acTypValAr(3) As TypedValue
    acTypValAr.SetValue(New TypedValue(DxfCode.Operator, "<or"), 0)
    acTypValAr.SetValue(New TypedValue(DxfCode.Start, "TEXT"), 1)
    acTypValAr.SetValue(New TypedValue(DxfCode.Start, "MTEXT"), 2)
    acTypValAr.SetValue(New TypedValue(DxfCode.Operator, "or>"), 3)

    '' 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("FilterForText")]
public static void FilterForText()
{
    // Get the current document editor
    Editor acDocEd = Application.DocumentManager.MdiActiveDocument.Editor;

    // Create a TypedValue array to define the filter criteria
    TypedValue[] acTypValAr = new TypedValue[4];
    acTypValAr.SetValue(new TypedValue((int)DxfCode.Operator, "<or"), 0);
    acTypValAr.SetValue(new TypedValue((int)DxfCode.Start, "TEXT"), 1);
    acTypValAr.SetValue(new TypedValue((int)DxfCode.Start, "MTEXT"), 2);
    acTypValAr.SetValue(new TypedValue((int)DxfCode.Operator, "or>"), 3);

    // 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 FilterForText()
    Dim sset As AcadSelectionSet
    Dim FilterType(3) As Integer
    Dim FilterData(3) As Variant
    Set sset = ThisDrawing.SelectionSets.Add("SS1")
 
    FilterType(0) = -4: FilterData(0) = "<or"
    FilterType(1) = 0: FilterData(1) = "TEXT"
    FilterType(2) = 0: FilterData(2) = "MTEXT"
    FilterType(3) = -4: FilterData(3) = "or>"
 
    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 13:11

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

返回顶部