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
Solved! Go to Solution.
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.
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!
I am not sure. Do you import DocumentExtension?!
Imports Autodesk.AutoCAD.ApplicationServices.DocumentExtension
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.