.NET

Reply
*Expert Elite*
norman.yuan
Posts: 943
Registered: ‎04-27-2009
Message 31 of 34 (136 Views)

Re: Launching AutoCad Issue

03-07-2013 08:26 PM in reply to: mgorecki

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

 

Autodesk.AutoCAD.ApplicationServices.Application.Quit()

 

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...).

Mentor
mgorecki
Posts: 399
Registered: ‎09-23-2004
Message 32 of 34 (127 Views)

Re: Launching AutoCad Issue

03-08-2013 07:36 AM in reply to: norman.yuan

Hi Norman,

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?

*Expert Elite*
norman.yuan
Posts: 943
Registered: ‎04-27-2009
Message 33 of 34 (123 Views)

Re: Launching AutoCad Issue

03-08-2013 08:12 AM in reply to: mgorecki

If you run the managed API code inside AutoCAD, then before you call Application.Quit(), you can close each document with method

 

Document.CloseAndDiscard()

 

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.

Mentor
mgorecki
Posts: 399
Registered: ‎09-23-2004
Message 34 of 34 (119 Views)

Re: Launching AutoCad Issue

03-08-2013 10:08 AM in reply to: norman.yuan

Hi Norman, Can I email you my code?  I just don't think I uhnderstand the whole COM thing.

 

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
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

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

Ask the Community