.NET

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

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

276 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

 

Valued Contributor
Posts: 80
Registered: ‎09-05-2012
Message 2 of 7 (271 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
Posts: 29
Registered: ‎10-01-2009
Message 3 of 7 (233 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
Posts: 80
Registered: ‎09-05-2012
Message 4 of 7 (223 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
Posts: 29
Registered: ‎10-01-2009
Message 5 of 7 (217 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
Posts: 80
Registered: ‎09-05-2012
Message 6 of 7 (213 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
Posts: 29
Registered: ‎10-01-2009
Message 7 of 7 (206 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.

 

You are not logged in.

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

Announcements
Welcome to the new Autodesk Community!
If this is your first visit, click here to get started and make the most of the Community. Let us know what you think of the new experience in the Community Feedback Forum.

Need installation help?

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

Ask the Community