Results 1 to 4 of 4

Thread: Copy a part of drawing, paste in another drawing keeping groups as they're

  1. #1
    Login to Give a bone
    0

    Default Copy a part of drawing, paste in another drawing keeping groups as they're

    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

  2. #2
    Administrator BlackBox's Avatar
    Join Date
    2009-11
    Posts
    5,719
    Login to Give a bone
    0

    Default Re: Copy a part of drawing, paste in another drawing keeping groups as they're

    Welcome to AUGI.

    Unfortunately, that is how Autodesk designed groups to work. Some possible ways around this, are to:

    Iterate the source group, creating a block, copy the block into the target drawing then iterate/explode the block, and recreate the group.

    XREF the source drawing into the target drawing, BIND it, then ERASE everything that you do not need.

    HTH
    "How we think determines what we do, and what we do determines what we get."

    Sincpac C3D ~ Autodesk Exchange Apps

    Computer Specs:
    Dell Precision 3660, Core i9-12900K 5.2GHz, 64GB DDR5 RAM, PCIe 4.0 M.2 SSD (RAID 0), 16GB NVIDIA RTX A4000

  3. #3
    Login to Give a bone
    0

    Default Re: Copy a part of drawing, paste in another drawing keeping groups as they're

    Hey BlackBox,
    Thank you. Recreating the group in the new drawing will take more time. That is why i was asked to automate the process. I don't know how to do that. Because, this is my second project on autocad. Can you guide me through a code?

  4. #4
    Administrator BlackBox's Avatar
    Join Date
    2009-11
    Posts
    5,719
    Login to Give a bone
    0

    Default Re: Copy a part of drawing, paste in another drawing keeping groups as they're

    Well, we are talking about ActiveX in lieu of .NET - taking more time to do the same work is expected. Haha

    If you're going to be developing code, this trio of DevBlog articles may be useful, and to demonstrate my comment on code performance/efficiency, this graphic from the 3rd article comes to mind... You see, I skipped VBA, jumping strait from AutoLISP/Visual LISP --> .NET API.




    That said, adding a Group is pretty straight forward... Remember the ActiveX Object Model is your friend.

    The Document Object's Groups Collection exposes an Add() Method - just scroll down to the 'Signature - All Other Supported Objects' section.

    Once you've copied the source Group's contents into the target Drawing, and created a Group in the target Drawing, you can call the new Group Object's AppendItems() Method.

    Cheers
    "How we think determines what we do, and what we do determines what we get."

    Sincpac C3D ~ Autodesk Exchange Apps

    Computer Specs:
    Dell Precision 3660, Core i9-12900K 5.2GHz, 64GB DDR5 RAM, PCIe 4.0 M.2 SSD (RAID 0), 16GB NVIDIA RTX A4000

Similar Threads

  1. Copy an paste Autocad drawing oBject by VBA
    By grobnik in forum VBA/COM Interop
    Replies: 5
    Last Post: 2019-07-30, 05:28 AM
  2. 2013: AutoCAD Drawing Size - copy/paste
    By walt.sparling in forum AutoCAD General
    Replies: 3
    Last Post: 2014-03-08, 07:05 PM
  3. Replies: 4
    Last Post: 2013-11-17, 09:49 PM
  4. COPY ONLY A PART OF BIG DRAWING
    By poymaasin in forum AutoCAD General
    Replies: 5
    Last Post: 2010-04-13, 08:00 PM
  5. Copy/paste of groups from view to another
    By some-1-2 in forum Revit Architecture - General
    Replies: 2
    Last Post: 2007-07-11, 08:01 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •