CAD开发者社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

ObjectARX 开发指南

使用选择筛选器定义选择集规则 (.NET)

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

选择过滤器由 形式的参数对组成。a 的第一个参数标识筛选器的类型(例如,对象),第二个参数指定要筛选的值(例如,圆圈)。筛选器类型是指定要使用的筛选器的 DXF 组代码。此处列出了一些最常见的筛选器类型。TypedValuesTypedValue

常见过滤器的 DXF 代码

DXF 代码

过滤器类型

0(或 DxfCode.Start)

对象类型(字符串)

如“线”、“圆”、“弧”等。

2(或 DxfCode.BlockName)

块名称(字符串)

插入参照的块名。

8 或 (DxfCode.LayerName)

图层名称(字符串)

如“第 0 层”。

60 (DxfCode.Visibility)

对象可见性(整数)

使用 0 = 可见,1 = 不可见。

62(或 DxfCode.Color)

颜色数字(整数)

数字索引值的范围为 0 到 256。

零表示 BYBLOCK。256 表示 BYLAYER。负值表示图层已关闭。

67

模型/图纸空间指示器(整数)

使用 0 或省略 = 模型空间,1 = 图纸空间。

为选择集指定单个选择条件

以下代码提示用户选择要包括在选择集中的对象,并筛选出除圆圈之外的所有对象。

VB.NET

Imports 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

路过

雷人

握手

鲜花

鸡蛋

最新评论

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

GMT+8, 2024-5-19 13:18

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

返回顶部