Results 1 to 6 of 6

Thread: Copy an paste Autocad drawing oBject by VBA

  1. #1
    Member
    Join Date
    2008-02
    Posts
    40
    Login to Give a bone
    0

    Default Copy an paste Autocad drawing oBject by VBA

    Hi to everybody,
    I'm searching for some sample code in order to copy all drawing objects into clipboard and paste into another drawing.

    Seem it's mission impossible with VBA embedded in Autocad.

    Thank you,

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

    Default Re: Copy an paste Autocad drawing oBject by VBA

    Can you not instead simply use the COPYBASE Command OOTB?
    "How we think determines what we do, and what we do determines what we get."

    Sincpac C3D ~ Autodesk Exchange Apps

    Computer Specs:
    Dell Precision 3620, Core i7-7700K 4.2GHz, 64GB RAM, Samsung 970 Pro M.2, 8GB NVIDIA Quadro P4000

  3. #3
    Member
    Join Date
    2008-02
    Posts
    40
    Login to Give a bone
    0

    Default Re: Copy an paste Autocad drawing oBject by VBA

    Quote Originally Posted by BlackBox View Post
    Can you not instead simply use the COPYBASE Command OOTB?
    Thank you for your answer, I have to replace some parts in 130 DWG !! so I'm searching something like a procedure, your command work fine, I'll try to use in a script....

    Thank you.

  4. #4
    Active Member
    Join Date
    2012-11
    Location
    Italy
    Posts
    65
    Login to Give a bone
    0

    Default Re: Copy an paste Autocad drawing oBject by VBA

    if sticking to VBA you could use the "CopyObjects" method of the Document or Database object
    the following code copies all object from the active document to a newly created one but you can simply adapt it to your needs
    Code:
    Option Explicit
    Sub CopyAllObjects()
    
    Dim sourceDwg As AcadDocument, destDwg As AcadDocument
    
    Set sourceDwg = ActiveDocument 
    Set destDwg = Documents.Add
    
    sourceDwg.CopyObjects allObjectsArray(selectAllObjects(sourceDwg)), destDwg.ModelSpace
        
    End Sub
    and here they are the called functions
    Code:
    Function selectAllObjects(myDoc As AcadDocument) As AcadSelectionSet
    
    Set selectAllObjects = CreateSelectionSet("mySel", myDoc)
    myDoc.Application.ZoomAll
    selectAllObjects.Select acSelectionSetAll
        
    End Function
    Code:
    Function allObjectsArray(ss As AcadSelectionSet)
    Dim iEnt As Long
    
    ReDim Objects(0 To ss.Count - 1) As AcadEntity
    For iEnt = 0 To ss.Count - 1
        Set Objects(iEnt) = ss.Item(iEnt)
    Next iEnt
    allObjectsArray = Objects
    
    End Function
    Code:
    Function CreateSelectionSet(SSset As String, Optional myDoc As Variant) As AcadSelectionSet
    If IsMissing(myDoc) Then Set myDoc = ThisDrawing
    
    On Error Resume Next
    Set CreateSelectionSet = myDoc.SelectionSets(SSset)
    If Err Then
        Set CreateSelectionSet = myDoc.SelectionSets.Add(SSset)
    Else
        CreateSelectionSet.Clear
    End If
    End Function

  5. #5
    Member
    Join Date
    2008-02
    Posts
    40
    Login to Give a bone
    0

    Default Re: Copy an paste Autocad drawing oBject by VBA

    Thank you RICVBA I'll try asap

  6. #6
    Member
    Join Date
    2019-05
    Posts
    15
    Login to Give a bone
    0

    Default Re: Copy an paste Autocad drawing oBject by VBA

    grobnik, still no luck?

Similar Threads

  1. 2013: AutoCAD Drawing Size - copy/paste
    By walt.sparling in forum AutoCAD General
    Replies: 3
    Last Post: 2014-03-08, 07:05 PM
  2. Replies: 4
    Last Post: 2013-11-17, 09:49 PM
  3. Copy / Paste object coordinates into text
    By IanR in forum AutoCAD Wish List
    Replies: 0
    Last Post: 2006-11-06, 09:32 PM
  4. Copy/Paste From Autocad
    By IanR in forum Inventor Wish List
    Replies: 0
    Last Post: 2006-08-07, 03:33 PM
  5. Copy/Paste Object Data
    By gis.68227 in forum AutoCAD Map 3D - Wish List
    Replies: 3
    Last Post: 2005-02-01, 03:21 PM

Posting Permissions

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