.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

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

6 REPLIES 6
SOLVED
Reply
Message 1 of 7
CADCC
1216 Views, 6 Replies

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

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 😞

 

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

 

6 REPLIES 6
Message 2 of 7
sszabo
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.

Message 3 of 7
CADCC
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!

 

 

Message 4 of 7
sszabo
in reply to: CADCC

I am not sure.  Do you import DocumentExtension?!

 

Imports Autodesk.AutoCAD.ApplicationServices.DocumentExtension

Message 5 of 7
CADCC
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

Message 6 of 7
sszabo
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.

Message 7 of 7
CADCC
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.

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost