Kean Walmsley

  • About the Author
    Kean on Google+

April 2014

Sun Mon Tue Wed Thu Fri Sat
    1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30      

« Initialization code in your F# AutoCAD application | Main | Using a jig to rotate an AutoCAD entity via .NET »

March 27, 2008

Embedding AutoCAD 2009 in a standalone dialog

This post takes a look at another topic outlined in this overview of the new API features in AutoCAD 2009.

AutoCAD 2009 introduces the ability to embed the application in a standalone dialog or form via an ActiveX control. This capability has been around for a number of releases of AutoCAD OEM, but this feature has now been made available in the main AutoCAD product.

The way the control works is to launch an instance of AutoCAD in the background (it should go without saying that AutoCAD needs to be installed on the system, but I've said it, anyway :-) and it then pipes the graphics generated by AutoCAD into the area specified by the bounds of the control. It also then pipes back any mouse movements or keystrokes, to allow the embedded AutoCAD to be controlled. It's pretty neat: you'll see the standard cursor, be able to enter commands via dynamic input, and more-or-less do whatever can be done inside the full product.

The control is especially handy if you want to present a reduced user-interface to the people using the product (which is really what AutoCAD OEM is for, in a nutshell, although the development effort involved in creating a full AutoCAD OEM application makes it inappropriate for quick & easy UI streamlining).

Let's start our look at this control by creating a new C# Windows Application project in Visual Studio 2005 (you can use whatever ActiveX container you like, though - it should even work from a web-page or an Office document):

New application project

Once Visual Studio has created the new project, we need to add our control to the toolbox. If you right-click on the toolbox, you'll be able to select "Choose Items...".

Add to toolbox

From here, there should be an item "AcCtrl" in the list of COM Components. Otherwise you can browse to it in c:\Program Files\Common Files\Autodesk Shared\AcCtrl.dll.

Add control to toolbox

Then you simply need to place the control on your form.

Add control to form

Once we've done that, we're going to add a few more controls - for the drawing path, and a text string for commands we want to try "posting" to the embedded AutoCAD application.

Design our form

Here's the C# code we'll use to drive the embedded control from the form. You should be able to work out what the various controls have been called in the project by looking at the code.

using System;

using System.Windows.Forms;

namespace EmbedAutoCAD


  public partial class MainForm : Form


    public MainForm()




    private void browseButton_Click(

      object sender, EventArgs e)


      OpenFileDialog dlg =

        new OpenFileDialog();

      dlg.InitialDirectory =


      dlg.Filter =

        "DWG files (*.dwg)|*.dwg|All files (*.*)|*.*";

      Cursor oc = Cursor;

      String fn = "";

      if (dlg.ShowDialog() ==



        Cursor = Cursors.WaitCursor;

        fn = dlg.FileName;



      if (fn != "")

        this.drawingPath.Text = fn;

      Cursor = oc;


    private void loadButton_Click(

      object sender, EventArgs e)


      if (System.IO.File.Exists(drawingPath.Text))

        axAcCtrl1.Src = drawingPath.Text;


        MessageBox.Show("File does not exist");


    private void postButton_Click(

      object sender, EventArgs e)






Finally, when we run the application and load a drawing via the browse/load buttons, the real fun starts. :-)

Embedded AutoCAD 2009

Try entering commands via dynamic input, or via the "Post a command" textbox. You might feel a little disorientated due to the lack of a command-line (I do love my command-line ;-), but dynamic input allows you to at least see what you're typing.

Here's the C# project for you to download.


TrackBack URL for this entry:

Listed below are links to weblogs that reference Embedding AutoCAD 2009 in a standalone dialog:

blog comments powered by Disqus

10 Random Posts