在屏幕上选择时查找组

Find Groups in when selected on screen

虽然我是 运行 我的代码,但我发现机械图纸中 selection 矩形中存在的组数在 autocad 绘图中如下所示。但是当我尝试使用 VBA 查找时,我找不到,因为 API 不可用。

Option Explicit Sub Group() 'Declaration Dim acApp As AcadDocument Dim acSeSet As AcadSelectionSet Set acApp = ThisDrawing.Application.ActiveDocument 'Selection Set Creation Set acSeSet = acApp.SelectionSets.Add("ShelSde4htd1") acSeSet.SelectOnScreen

当我 运行 这部分代码进入屏幕时,要求我 select 屏幕上的部分。我能够从这个 selection 中获取实体,但不能从组中获取实体。我知道组也是一个集合,但是我可以从屏幕上的 selection 中获取组 selection 吗?

    Dim acEnt As AcadEntity
    Dim entity_handle() As String
    Dim i As Integer
    i = 0
    Dim entity_count As Integer
    entity_count = acSeSet.Count()          'Selection Set Count
    ReDim entity_handle(entity_count)       'Resizing the entity handle array
    For Each acEnt In acSeSet               'Iterating through selected entities and storing in one array, the handles
        entity_handle(i) = acEnt.Handle
         i = i + 1
    Next

在这里我可以获取实体,但除此之外我还想获取该地区的群组 selected。

VBA的SelectionSet对象只能select个图形元素 组不是图形元素,它们是(命名的)selectionset 本身!

要获得可能的 selected 组,您必须遍历 selectionset 的每个元素并检查它是否属于某个组。然后,如果您需要确保整个组都被 selected,您必须检查该组的所有元素是否都属于 selectionset。

这是相当多的多次迭代:如果您的绘图有很多组 and/or 组中有许多元素,那么您最好研究最合适的搜索技术(存储组元素的数组?)