I am trying to copy and paste selected part of a drawing to another drawing keeping in mind that the groups should remain as they're in the first drawing. I am following the approach:
1. Select entities and cycle through them to collect the handles.
2. Collect all the groups in first drawing, and cycle through them and also inside of it the attached entities inside the group and get the handles.
My next tasks are:
3. Compare two handles and if matches, it means those particular groups attached to selected entities are selected.
4. Store selected group names, and entities inside arrays, copy them open a new drawing, paste them using insertion point, ensuring the pasted entities have the same groups as they were in the first drawing.
I tried following code (Upto step 2):
Code:
Option Explicit
'Declarations
Sub Group()
Dim acApp As AcadDocument
Set acApp = ThisDrawing.Application.ActiveDocument
'Creating Selection Set
Dim acSelSet As AcadSelectionSet
Set acSelSet = acApp.SelectionSets.Add("sset")
acSelSet.SelectOnScreen
Dim selection_count As Integer
selection_count = acSelSet.Count()
'Cycling through selected entities
Dim acEnt As AcadEntity
For Each acEnt In acSelSet
acEnt.Handle
Next
'Cycling through groups, and getting handle for entitties attached to the group
Dim acGroup As AcadGroup
Dim acGroupEnt As AcadEntity
For Each acGroup In ThisDrawing.Groups
Debug.Print ("Group Name: " & acGroup.Name)
For Each acGroupEnt In acGroup
Debug.Print (" " & acGroupEnt.ObjectName & " ... " & acGroupEnt.Handle)
Next
Next
'Creation of group object
'Dim acGroup As AcadGroup
'Dim acgroup As AcadGroups
'Dim group_count As Integer
'Set acgroup =
'group_count = acgroup.Count()
'Dim i As Integer
'Dim group_name As Variant
'For i = 0 To group_count
' group_name = acgroup(i).Name
' acObj = acgroup.Item(i)
'Next i
'Dim group_count As Integer
'group_count = acGroup.Count()
'Dim group_name As String
'For Each acGroup In acSelSet
' group_name = acGroup.Name()
'Next
'Dim group_count As Integer
'group_count = acGroup.Count
acSelSet.Delete
'acGroup.Delete
End Sub
If someone have solutions to my problem, please let me know. I am new to AutoCAD customization. Also, if someone have different approaches to solve the problems, it could be a great help. Thanks