Running AutoCAD inside Revit

The preceding post on RealDWG and object enablers discussed one potential method for making use of AcDb functionality to read and write AutoCAD DWG files inside of Revit. Assuming that you have a license for a full version of AutoCAD in addition to your Revit one, there is another easy method to achieve this which has been implemented and tested.

It is possible to run AutoCAD as a full-blown process in the background inside Revit. This functionality is new in AutoCAD 2009, and the code we present is based on a demo by Kean Walmsley on embedding AutoCAD 2009 in a standalone dialog. Obviously this requires a full version of AutoCAD to be installed on the machine. Among other things, Kean's code defines a MainForm class, which can be used to load and run AutoCAD and access its API functionality.

Markus Hannweber of SOFiSTiK AG has made use of this within a Revit plug-in. Here are some examples of what is possible:

MainForm mainform = new MainForm();
AxACCTRLLib.AxAcCtrl c = mainform.axAcCtrl1;
c.Src = "d:\\demo\\embed.dwg";
c.PostCommand("(setvar \"cmddia\" 0) ");
c.PostCommand("(arxload\"sofibldarx\") ");
c.PostCommand("(load\"blist\") ");
c.PostCommand("SOF_BLIST ");
c.PostCommand("(S:ENDACAD) ");
c.Src = null;

The individual lines do the following:

Obviously, the actions you trigger in your background AutoCAD process must not require any user interaction, or, if they do, you must feed them the appropriate command line user input through something like mainform.axAcCtrl1.PostCommand(...).

Der Grund für das alles:

Das ganze Projekt kann ich natürlich nicht schicken, der wesentliche Unterschied zu Kean ist, dass ich die Dialogbox mit ACAD (MainForm) nicht aufmache! In MFC würde ich sagen ich lasse einfach DoModal weg. (.NET Befehl hab ich vergessen) Bei Kean geht die Dialogbox auf und zeigt ACAD zunächst ohne alle Menüs, aber im wesentlichen ist alles bearbeitbar. Aber einfach, gucke da, da stehen sogar einige meiner Fragen drauf.