.NET

Reply
*Expert Elite*
Alfred.NESWADBA
Posts: 9,070
Registered: ‎06-29-2007
Message 11 of 12 (224 Views)

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

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

Hi,

 

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")
      DbxDoc.Open(tSourceFileName)

      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)
            Debug.Print(entry.Name)
         End If
      Next entry

   End Sub

 

- alfred -

-------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at
-------------------------------------------------------------------------
Active Member
taiven
Posts: 9
Registered: ‎11-22-2012
Message 12 of 12 (214 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

 

Objects(0)=entry

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

 

Fantastic!

 

Thanks.

Announcements
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 or visit the Installation and Licensing Forum to get help installing your software.