VBA
Discuss AutoCAD ActiveX and VBA (Visual Basic for Applications) questions here.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Copy objects from one drowing to another - GetInterfaceObject method.

3 REPLIES 3
SOLVED
Reply
Message 1 of 4
bojko108
1092 Views, 3 Replies

Copy objects from one drowing to another - GetInterfaceObject method.

Hello. I'm using this function to copy blocks from one drawing to another. It works in AutoCAD 2004, 2006 but I need to know whether will it work in AutoCAD 2010. This is the code that I use and my question is if I add these lines to check version is the method will work or not.

If Left(Application.Version, 2) = "18" Then
    Set oDbx = GetInterfaceObject("ObjectDBX.AxDbDocument.18")
End If

 

 

 

Here is the full program:


Private Sub CopyBlock(BlockName As String)
     Dim oDbx As Object
        ' 2007 - 2009 ver.
        If Left(Application.Version, 2) = "17" Then
           Set oDbx = GetInterfaceObject("ObjectDBX.AxDbDocument.17")
        End If

        ' 2004 - 2006 ver.
        If Left(Application.Version, 2) = "16" Then
           Set oDbx = GetInterfaceObject("ObjectDBX.AxDbDocument.16")
        End If

     Dim fname As String
           fname = "C:\BojkoCAD\blocks.dwg"

           oDbx.Open fname

     Dim oBlocks As AcadBlocks
     Dim oBlock As AcadBlock
     Dim copyVar(0) As AcadBlock
     Set oBlocks = oDbx.Blocks
     Set oBlock = oBlocks.Item(BlockName)
     Set copyVar(0) = oBlock

On Error GoTo problem

     Dim idPairs As Variant
     Dim copyBLK As Variant
            copyBLK = oDbx.CopyObjects(copyVar, ThisDrawing.Blocks, idPairs)
     Set oDbx = Nothing

problem:
     If Err.Number <> 0 Then
        MsgBox "ObjectDBX CopyObjects method objects failed." & vbCr & Err.Number & " " & Err.Description, vbCritical, "BojkoCAD"
     End If

End Sub



 

 

3 REPLIES 3
Message 2 of 4
Hallex
in reply to: bojko108

Just an idea not tested

Set oDbx = GetInterfaceObject("ObjectDBX.AxDbDocument.18.2")

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Message 3 of 4
bojko108
in reply to: bojko108

Thank you I test it and works fine.

Message 4 of 4
Hallex
in reply to: bojko108

Glad to help

Happy coding Smiley Happy 

~'J'~

_____________________________________
C6309D9E0751D165D0934D0621DFF27919

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost