Reputation: 99
While i was running my code, i found that the number of groups present in the selection rectangle in mechanical drawings, are shown below in autocad drafting. But when i try to find using VBA, i couldn't because of unavailability of 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
When i am running this part of code it goes to screen, and ask me to select the part on the screen. I am able to get entities from this selection but not the groups. I know group is also a collection, but can i then get the group selection from the selection on the screen?
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
Here i can get the entities, but apart from it i also want to get the groups selected in that region.
Upvotes: 0
Views: 684
Reputation: 29421
VBA's SelectionSet object can only select graphic elements and groups are not graphic elements, they're (named) selectionset themselves!
to get possibly selected groups you must iterate through each element of the selectionset and check whether it belongs to a Group. then, if you need to make sure the whole group is selected you must check whether all elements of that group belongs to selectionset.
it's quite a bunch of multiple iterations: if your drawing has many groups and/or many elements in groups then you'd better investigate the best suitable searching technique (arrays to store groups elements?)
Upvotes: 1