增加筛选器列表条件的复杂性 (.NET) 
指定多个选择条件时,AutoCAD 假定所选对象必须满足每个条件。您可以通过其他方式限定您的标准。对于数值项,可以指定关系运算(例如,圆的半径必须大于或等于 5.0)。对于所有项目,您可以指定逻辑运算(例如,或 )。TextMText 使用 -4 DXF 代码或常量指示选择筛选器中的关系运算符。运算符表示为字符串。允许的关系运算符如下表所示。DxfCode.Operator 
 选择筛选器中的逻辑运算符也由 -4 组代码或常量 表示,运算符是字符串,但运算符必须成对。开始运算符前面有一个小于符号 (<),结束运算符后面跟着一个大于符号 (>)。下表列出了选择集筛选中允许的逻辑运算符。DxfCode.Operator 
 选择半径大于或等于 5.0 的圆以下示例选择半径大于或等于 5.0 的圆。 VB.NETImports 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 代码参考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
选择“文本”或“MText”下面的示例指定可以选择 or 对象。TextMText VB.NETImports 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
相关概念父主题: | ||||||||||||||||||||||||||||||||||||||||||||
|Archiver|CAD开发者社区
( 苏ICP备2022047690号-1   苏公网安备32011402011833)
GMT+8, 2025-11-4 23:12
Powered by Discuz! X3.4
Copyright © 2001-2021, Tencent Cloud.