.NET

.NET

Reply
Active Contributor
CADCC
Posts: 29
Registered: ‎10-01-2009
Message 1 of 7 (562 Views)
Accepted Solution

Switching from VBA to VB.NET - Urgent help required with ThisDrawing property

562 Views, 6 Replies
12-12-2013 07:38 AM

Hi

 

I've been writing programs in VBA for years and consider myself to be reasonably proficient.  I'm not attempting to make the switch over to vb.net.  I've messed around with .net to write a couple of windows apps and all in all, it's gone pretty well and I actually prefer using it to vba.

 

However, I now want to use vb.net to re-write some old autocad vba programs and at the same time, improve and enhance them.  I'm using AutoCAD 2013 with Vis Studio 2010 Express, with the ObjectARX 2013 installed along with the templates I got from the autodesk website.  I'm seriously struggling to get started as I cannot seem to get hold of the .net equivalent to ThisDrawing.

 

I want to set up a public property called ThisDrawing, just to make things a bit simpler and help with my mental transission from vba but I'm finding it impossible to do :smileysad:

 

All the examples I've found say to use...

 

Public readonly property ThisDrawing() as AcadDocument

Get

Return Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.AcadDocument

End Get

End Property

 

...but this wouldn't work as 'AcadDocument' was not available under MdiActiveDocument.  More digging on google turns up that it's now been replaced with GetAcadDocument but that was unavailable.  I then discovered that I was missing two references (way to go templates!) those being  Autodesk.AutoCAD.Interop.dll and .Common.dll, which helped after adding a couple of additional imports to my module, but I still cannot find out how to set up a new property called ThisDrawing which is assigned to the current active autocad document.

 

Can anyone please put me out of my misery with this as it's driving me mad.  I don't know if i'm still missing references, something's a bit screwy between .net and autocad, or if I'm just being too ignorant.

 

Any and all help gratefully received.

 

Regards

 

Graham

 

Oh, now I see, my bad, it's my abbreviation, that I didn't notice before:

 

Imports MgdAcApplication = Autodesk.AutoCAD.ApplicationServices.Application

 

Let me know if this works for you.  Looks like you are on the  right track.

Valued Contributor
sszabo
Posts: 86
Registered: ‎09-05-2012
Message 2 of 7 (557 Views)

Re: Switching from VBA to VB.NET - Urgent help required with ThisDrawing propert

12-12-2013 08:28 AM in reply to: CADCC

In 2013 you should be using DocumentExtension as such:

 

    Private Shared ReadOnly Property ThisDrawing() As AcadDocument
        Get
            Return DocumentExtension.GetAcadDocument(MgdAcApplication.DocumentManager.MdiActiveDocument)
        End Get
    End Property

 

Then you can use it like this:

 

ThisDrawing.SendCommand("Hello World" & vbCrLf)

 

More discussion of this can be found here.

Active Contributor
CADCC
Posts: 29
Registered: ‎10-01-2009
Message 3 of 7 (519 Views)

Re: Switching from VBA to VB.NET - Urgent help required with ThisDrawing propert

12-13-2013 01:25 AM in reply to: sszabo

Thanks for the suggestion.  Unfortuantely the... 

MgdAcApplication.DocumentManager.MdiActiveDocument

...is not available to me when I open brackets after GetAcadDocument.

 

Any ideas why not?

 

Cheers!

 

 

Valued Contributor
sszabo
Posts: 86
Registered: ‎09-05-2012
Message 4 of 7 (509 Views)

Re: Switching from VBA to VB.NET - Urgent help required with ThisDrawing propert

12-13-2013 05:18 AM in reply to: CADCC

I am not sure.  Do you import DocumentExtension?!

 

Imports Autodesk.AutoCAD.ApplicationServices.DocumentExtension

Active Contributor
CADCC
Posts: 29
Registered: ‎10-01-2009
Message 5 of 7 (503 Views)

Re: Switching from VBA to VB.NET - Urgent help required with ThisDrawing propert

12-13-2013 06:46 AM in reply to: sszabo

Yes I am.

 

Here's a screen shot of the module (which is the only code in the project)

 

vb grab.jpg

Valued Contributor
sszabo
Posts: 86
Registered: ‎09-05-2012
Message 6 of 7 (499 Views)

Re: Switching from VBA to VB.NET - Urgent help required with ThisDrawing propert

12-13-2013 06:59 AM in reply to: CADCC

Oh, now I see, my bad, it's my abbreviation, that I didn't notice before:

 

Imports MgdAcApplication = Autodesk.AutoCAD.ApplicationServices.Application

 

Let me know if this works for you.  Looks like you are on the  right track.

Active Contributor
CADCC
Posts: 29
Registered: ‎10-01-2009
Message 7 of 7 (492 Views)

Re: Switching from VBA to VB.NET - Urgent help required with ThisDrawing propert

12-13-2013 07:56 AM in reply to: sszabo

That's spot on!

 

It's a shame that Autodesk don't put that in their templates.

 

 

Thanks very much indeed.

 

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.