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:

  • Instantiate Kean’s MainForm class and open AutoCAD in the background.
  • Initialise a variable ‘c’ to address the AutoCAD control. It also helps keep the source code line length under control.
  • Load a drawing, object enablers are automatically loaded with it, if set up to do so.
  • Suppress AutoCAD command line output.
  • Load an ARX application into AutoCAD.
  • Load an AutoLISP application into AutoCAD.
  • Start any application command, whether defined in Lisp or ARX.
  • Run a command to reset the ‘drawing dirty’ flag, so the next command can quit AutoCAD without user interaction.
  • Close AutoCAD.

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


Comments

14 responses to “Running AutoCAD inside Revit”

  1. Blogs are good for every one where we get lots of information for any topics nice job keep it up !!!

  2. Hi, and thank you for the appreciation, it feels good! Cheers, Jeremy.

  3. Excellent Blog every one can get lots of information for any topics from this blog nice work keep it up.

  4. Very glad you like it! Cheers, Jeremy.

  5. Nice blog, its great article informative post, thanks for sharing it. Thanks for the information!

  6. Dear Term paper,
    And thank you for you appreciation!
    Cheers, Jeremy.

  7. Hi Jeremy,
    Could you tell us how to implement a command to reset the ‘drawing dirty’ flag. I dont seem to find any link to that.
    Thx,
    Kris

  8. Dear Kris,
    I have sent off a query to my colleagues to find out, but no answer yet. I do not believe it is currently possible, unfortunately.
    Cheers, Jeremy.

  9. Dear Kris,
    By the way, how about simply saving the document to reset the IsModified flag?
    Cheers, Jeremy.

  10. jala srikanth Avatar
    jala srikanth

    jeremy do you knoe easy methods in autocad 2009

  11. Dear Jala,
    Nope, sorry. You might try the AutoCAD discussion groups, or Kean’s blog Through the Interface:
    http://discussion.autodesk.com
    http://through-the-interface.typepad.com/through_the_interface
    Cheers, Jeremy.

  12. Hi Jeremy!
    I develope tools to autocad 2010 and liked a lot of topic: “embedding AutoCAD 2009 in a standalone dialog”. It’s working very good in vb6 language, but I got some problem related to release basic functions by textEdit simulating a cad’s prompt. Some callbacks are slowing work on graphic screen. Do I need compilate a vb6 like class and creatind a dll file ?
    Thanks!

  13. Hi Jeremy !
    Do you know how can I cancel F2 command while using acCtlr?
    Everytime I press key F2, so it lanch editor environment to front my aplication. I’d like avoid this happen.
    Some idea?
    Thanks.

  14. Dear Xavier,
    I have absolutely no idea, and I do not really use acCtrl myself.
    I am sure you can install some Windows hook or something to catch and trap this key hit, but no idea how.
    You might want to ask Kean on his blog, which is more directed at AutoCAD and its APIs:
    http://through-the-interface.typepad.com/through_the_interface
    Or you can try the discussion forums:
    http://forums.autodesk.com
    Good luck!
    Cheers, Jeremy.

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading