I am currently creating a windows form application that needs to open autocad .I have done it for Autocad 2014.Is there any way we can do this task workable not just for single version but for any version.In addition to this I have created dll for 2014 which worked fine.By altering the references acmgd.dll and acdbmgd.dll i got it worked on 2007 too.Is there any way except this to create a dll orking in all version.Thanks in advance.
-
Do you just want to *launch* Autocad, or do you want to *control* it? – Hans Kesting Jul 20 '16 at 08:00
-
Once i am able to launch no problem in controlling. – Roji Kayastha Jul 21 '16 at 06:15
2 Answers
For your first question, here are some suggestions:
- AutoCAD via COM API, where you can launch and control the application. Here is a nice tutorial, note the version string can be changed on runtime, but to support multiple versions, you'll need Late-binding (dynamic on C#).
- AutoCAD Console (aka AutoCAD via command line), available since version 2013, is the best way to automate AutoCAD from another application.
- Forge Design Automation API is the AutoCAD "on the cloud", best if you don't have AutoCAD installed on yours or on the customer's machine.
If you go with #1, the best way is via late-binding, so you don't have any reference on your app (don't use AcMgd, AcDbMgd or AcCoreMgd, use only the Autodesk.AutoCAD.Interop libraries). For #2 you'll need all three references (as the console is available since version 2013). For #3 you just need to call a webservice, so no Autodesk reference at all (cleanest).
For your second question, you'll need to compile your application twice, at least: for AutoCAD 2012 and older, and again for AutoCAD 2013 and newer. The first with AcMgd and AcDbMgd, and the second just add AcCoreMgd.

- 8,493
- 2
- 17
- 44
One way to potentially achieve this is to find out which program is associated with Autocad files. This can be found by calling FindExecutable passing in a filename with an autocad file extension.
Once you have the executable to use you could launch it using Process.Start
Import as follows:
[DllImport("shell32.dll", EntryPoint = "FindExecutable")]
private static extern long FindExecutable(string lpFile, string lpDirectory, StringBuilder lpResult);

- 10,496
- 7
- 44
- 72