I thought I knew what you are trying to do from previous posts, but the code you showed made me more confused: your code is a CommandMethod from acad managed API and can only run inside AutoCAD (after the DLL is netloaded). Tell me: why when the code is already running IN AutoCAD, yet your code still try to get an AutoCAD instance (and if failed, try to create one). It is like the running AutoCAD does not know itself is an AutoCAD session. Why?
BTW, if you are running NETLOADED managed code, yes, you can close AutoCAD by calling
Let us clear things up:
You need to start AutoCAD from an external application (in your case, it is the web server application. If so, I mean, if the AutoCAD is to run in a unattented server by a server process, it is dangerous, because AutoCAD is designed as desktop app and offten need user to respond possible message popups. Not to mention the license policy may prohibite using AutoCAD this way), and control AutoCAD to do something and close it when done.
Without making things more complicated, you just need to automate AutoCAD via its COM API from the external application. And yes, you can build all the work (launching AutoCAD, open drawing to do something, saving/closing the drawing and then quitting AutoCAD) in a DLL (with referene to AutoCAD Type libabry/AutoAD ObjectDBX Common Type libabry - they are COM libraries) and load this DLL into the external app or web server(I do hope not).
In this case, no AutoCAD managed .NET API can be used (unless you do not mind to make things more complicated and insist to use managed API - then you need to expose your managed code as COM and properly registered it, and also make sure it is loaded into AutoCAD on startup...).
Thanks for responding. I'm sorry my post was so confusing. I added the "launch AutoCad" section thinking I needed to have an external program call my dll to launch AutoCad in order to eventually quit out.
I tried the "Autodesk.AutoCAD.ApplicationServices.Application.Quit()" line, but it always creates a pop-up asking if I want to save. I have already saved the drawing prior to the quit command.
Do you know how I can avoid the pop up?
If you run the managed API code inside AutoCAD, then before you call Application.Quit(), you can close each document with method
Make sure the code runs in session context (e.g. the CommandMethod takes a CommandFlags.Session argument).
You can also use Document Pop/PushDbmod() method to reset system variable "DBMODE" of a drawing to 0 (no change), before quitting.
Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register