Closing AutoCAD from VB.NET

Closing AutoCAD from VB.NET

Anonymous
Not applicable
2,692 Views
3 Replies
Message 1 of 4

Closing AutoCAD from VB.NET

Anonymous
Not applicable

I am using VB.NET 2010 and AutoCAD OEM 2014 (though for Development I use regular AutoCAD 2014).  I run Visual Studio, and it opens AutoCAD automatically.  Then I NETLOAD my app, which opens a new vb.net form.  Then my user can draw different entitites onto the AutoCAD pallette.

 

Of course it's easy to close the VB form, but how can I close the full AutoCAD program programatically from my VB form?  I've tried AcadApp.Quit() from my VB form but it does nothing.

 

The reason that this is important not to leave it to the user to close it is that I check for a valid license from VB, and if there is none, I don't want the user to be able to continue to use AutoCAD.

 

Also, what/where is the reference manual to find examples of using VB.NET and AutoCAD?

 

thanks in advance!

Mitch

0 Likes
Accepted solutions (1)
2,693 Views
3 Replies
Replies (3)
Message 2 of 4

Hallex
Advisor
Advisor
Handle Form_Closing event either for modal or modeless form:
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
Autodesk.AutoCAD.ApplicationServices.Application.Quit();
}
_____________________________________
C6309D9E0751D165D0934D0621DFF27919
0 Likes
Message 3 of 4

Anonymous
Not applicable
Accepted solution
That will probably work 99% of the time except if autocad is stuck on some command. I think Environment.Exit(0) will "brute force" close it no matter what.
Message 4 of 4

Anonymous
Not applicable

Environment.Exit(0)  seems to work nicely, and I like the 'brute force' approach since the user no longer has valid use of the program if it reaches this point.  Thanks very much!

0 Likes