.NET

Reply
Active Member
taiven
Posts: 9
Registered: ‎11-22-2012
Message 1 of 12 (508 Views)

How to copy blocks using VB.NET through COM?

508 Views, 11 Replies
11-22-2012 09:38 PM

Hi, all:

 

I got a question about access AUTOCAD through COM.

Previously I have one VB6 program, which read blocks from an external dwg files and insert into AUTOCAD2010's activepage.

Now I want to upgrade to VB.NET2010, but found one big problem cannot be resolved, that is, how to copy blocks from an external dwg files?


I use the command below to copy blocks from dwg file:

Call GetBlocksFromDwg("d:\abc.dwg", obj_Doc)

obj_'s definition is:

Dim obj_Doc As Autodesk.AutoCAD.Interop.AcadDocument


Previous VB6 source codes:

Private Sub GetBlocksFromDwg(DwgName As String, Target As Object)

Set DbxDoc = obj_Acad.GetInterfaceObject("ObjectDBX.AxDbDocument.18")

DbxDoc.Open DwgName

Dim Objects(0 To 0) As Object

For Each entry In DbxDoc.Blocks

    Set Objects(0) = DbxDoc.Blocks(entry.Name)

    DbxDoc.CopyObjects Objects, Target.Blocks

Next

End Sub

Current VB.NET 2010's source codes:

Private Sub GetBlocksFromDwg(ByRef DwgName As String, ByRef Target As Object)

Dim entry As Object

Dim DbxDoc As Object

DbxDoc = obj_Acad.GetInterfaceObject("ObjectDBX.AxDbDocument.18")

DbxDoc.Open(DwgName)

Dim Objects(0) As Object
For Each entry In DbxDoc.Blocks

  Objects(0) = DbxDoc.Blocks(entry.Name)

  CopyObjects(Objects, Target.Blocks, Type.Missing)

Next entry

End Sub

 

The command below cannot work:

CopyObjects(Objects, Target.Blocks, Type.Missing)

 

Please advise, thanks a lot.

 

*Expert Elite*
Alfred.NESWADBA
Posts: 8,982
Registered: ‎06-29-2007
Message 2 of 12 (497 Views)

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

11-22-2012 11:08 PM in reply to: taiven

Hi,

 

>>>there<<< you find a sample for .NET (I would prefere that instead of COM)

 

- alfred -

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

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

11-22-2012 11:10 PM in reply to: taiven

Hi, Alfred:

 

The problem is I composed an application EXE to access AutoCAD, so COM is the only method.

*Expert Elite*
Alfred.NESWADBA
Posts: 8,982
Registered: ‎06-29-2007
Message 4 of 12 (489 Views)

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

11-22-2012 11:13 PM in reply to: taiven

Hi,

 

my method of an EXE would be to just start AutoCAD, then load my DLL and let the DLL do the work :smileywink:

But let's see if someone is coming with a ready COM-code.

 

- alfred -

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

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

11-22-2012 11:15 PM in reply to: Alfred.NESWADBA

Yeah, hoping someone can resolve the problem.

*Expert Elite*
Alfred.NESWADBA
Posts: 8,982
Registered: ‎06-29-2007
Message 6 of 12 (481 Views)

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

11-23-2012 12:02 AM in reply to: taiven

Hi,

 

>> The command below cannot work:

>> CopyObjects(Objects, Target.Blocks, Type.Missing)

Have not tried that, but why did you change the VB6-Code from that line when converting?

DbxDoc.CopyObjects(Objects, Target.Blocks, Type.Missing)

 

What error message do you get?

 

- alfred -

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

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

11-23-2012 12:14 AM in reply to: Alfred.NESWADBA

error message: invalid object array

*Expert Elite*
Alfred.NESWADBA
Posts: 8,982
Registered: ‎06-29-2007
Message 8 of 12 (475 Views)

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

11-23-2012 12:16 AM in reply to: taiven

Hi,

 

you get this message with both versions of code?

DbxDoc.CopyObjects Objects, Target.Blocks

CopyObjects(Objects, Target.Blocks, Type.Missing)

 

BTW: what version of AutoCAD do you use?

 

- alfred -

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

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

11-23-2012 12:25 AM in reply to: Alfred.NESWADBA

DbxDoc.CopyObjects Objects, Target.Blocks

is converted to

DbxDoc.CopyObjects(Objects, Target.Blocks)

 

and

CopyObjects(Objects, Target.Blocks, Type.Missing) is illegal.

 

I use AutoCAD 2010, with VB.net 2010.

 

 

 

Active Member
taiven
Posts: 9
Registered: ‎11-22-2012
Message 10 of 12 (466 Views)

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

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

Just add some test codes.

you may copy aaa.dwg to c:\, or just change the location for the dwg file.

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.