*Expert Elite*
Posts: 8,890
Registered: ‎06-29-2007
Message 11 of 12 (211 Views)

Re: How to copy blocks using VB.NET through COM?

11-23-2012 01:30 AM in reply to: taiven



I tried it that way and it worked (with a button in the form), I hope for you too :smileywink:


   Const tSourceFileName As String = "C:\TEMP\X01.DWG"
   Const tDestFileName As String = "C:\TEMP\X02.DWG"

   Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click

      Dim obj_Acad As AcadApplication = CType(GetObject(, "AutoCAD.Application.18"), AcadApplication)
      Dim TargetDoc As AcadDocument = obj_Acad.Documents.Open(tDestFileName)

      Dim DbxDoc As Object = obj_Acad.GetInterfaceObject("ObjectDBX.AxDbDocument.18")

      Dim Objects(0) As Common.AcadBlock
      For Each entry As Common.AcadBlock In CType(DbxDoc.Blocks, IEnumerable)
         If (Not entry.IsLayout) AndAlso (Not entry.Name.StartsWith("*")) Then
            Objects(0) = entry
            DbxDoc.CopyObjects(CObj(Objects), TargetDoc.Blocks)
         End If
      Next entry

   End Sub


- alfred -

Ingenieur Studio HOLLAUS ... www.hollaus.at
Active Member
Posts: 9
Registered: ‎11-22-2012
Message 12 of 12 (201 Views)

Re: How to copy blocks using VB.NET through COM?

11-23-2012 05:45 AM in reply to: Alfred.NESWADBA

Hi, Alfred:


Thanks a lot, it works.

The key is:

dim entry as acadblock

dim Objects(0) as acadblock



DbxDoc.CopyObjects(CObj(Objects), TargetDoc.Blocks)





You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community