使用选择筛选器定义选择集规则 (.NET) 
选择筛选器由成对的参数组成,其形式为 。a 的第一个参数标识筛选器的类型(例如,对象),第二个参数指定要筛选的值(例如,圆)。筛选器类型是指定要使用的筛选器的 DXF 组代码。此处列出了一些最常见的过滤器类型。TypedValuesTypedValue 
 为选择集指定单个选择条件以下代码提示用户选择要包含在选择集中的对象,并筛选出除圆圈之外的所有对象。 VB.NETImports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.EditorInput
 
<CommandMethod("FilterSelectionSet")> _
Public Sub FilterSelectionSet()
    '' Get the current document editor
    Dim acDocEd As Editor = Application.DocumentManager.MdiActiveDocument.Editor
    '' Create a TypedValue array to define the filter criteria
    Dim acTypValAr(0) As TypedValue
    acTypValAr.SetValue(New TypedValue(DxfCode.Start, "CIRCLE"), 0)
    '' 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("FilterSelectionSet")]
public static void FilterSelectionSet()
{
    // Get the current document editor
    Editor acDocEd = Application.DocumentManager.MdiActiveDocument.Editor;
    // Create a TypedValue array to define the filter criteria
    TypedValue[] acTypValAr = new TypedValue[1];
    acTypValAr.SetValue(new TypedValue((int)DxfCode.Start, "CIRCLE"), 0);
    // 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 FilterSelectionSet()
    ' Create a new selection set
    Dim sset As AcadSelectionSet
    Set sset = ThisDrawing.SelectionSets.Add("SS1")
 
    ' Define the filter list, only Circle objects
    ' will be selectable
    Dim FilterType(0) As Integer
    Dim FilterData(0) As Variant
    FilterType(0) = 0
    FilterData(0) = "Circle"
 
    ' Prompt the user to select objects
    ' and add them to the selection set
    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 20:09
Powered by Discuz! X3.4
Copyright © 2001-2021, Tencent Cloud.