.NET

Reply
*Expert Elite*
Alfred.NESWADBA
Posts: 9,216
Registered: ‎06-29-2007
Message 11 of 12 (225 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 (215 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.

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.