Through the Interface: AU Handouts: There's More to .DWG Than AutoCAD - Part 3

May 2015

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


« AU Handouts: There's More to .DWG Than AutoCAD® - Part 2 | Main | "AutoCAD: 10 easy ways to crash your AutoCAD addin" webcast recording available for download »

October 24, 2007

AU Handouts: There's More to .DWG Than AutoCAD® - Part 3

[This post continues from part 1 and part 2 of this series.]

Building a full editing product using AutoCAD OEM

Now we’re going to take our AutoCAD .NET module from the beginning of the session and build a complete CAD package around it.

AutoCAD OEM allows you to build a custom-branded version of AutoCAD, with the subset of AutoCAD’s own features and additional functionality you choose to build in. A key feature of AutoCAD OEM is its security layer, which will stop any module being loaded that has not been built in by design. By limiting its extensibility – and allowing a subset of standard functionality to be enabled – ISV (Independent Software Vendor) partners are able to sell products based on AutoCAD OEM at a lower price-point.

This is, for example, how we build AutoCAD LT and DWG TrueView: they are both “cut down” versions of AutoCAD built using the AutoCAD OEM engine.

So let’s take a look at how to create an AutoCAD OEM product. We want to build an application that only contains AutoCAD’s 3D editing & visualization functionality, with our additional application logic added, to provide some in-built analysis of our models.

To get started, we launch the OEM Make Wizard. This tool depends on some Visual Studio environment variables to be set, so the simplest way is to launch it from a Visual Studio 2005 Command Prompt. I typically set the working directory for the command prompt to the root AutoCAD OEM folder (in my case “C:\Program Files\Autodesk\AutoCAD OEM 2008”) and then launch the tool by typing in “toolkit\oemmakewizard”.

On the first page of the Wizard we specify a name for our product. We’ll use “Solids”: this short name will be used for the executable name, for instance (i.e. Solids.exe, rather than acad.exe).


Figure 10 – starting a project with the OEM Make Wizard

On the next page we specify some additional details, such as a longer product name and version numbers. You can get more information on this from the AutoCAD OEM documentation.


Figure 11 – entering project information in the OEM Make Wizard

Next we specify the standard commands we want enabled. There are different levels of command support – None, Internal Use, Full and Redefine. Internal Use means we will call it programmatically, but don’t want the command directly usable by the user, and Redefine means we want the command to be usable but we will provide our own implementation. It should be obvious what None and Full mean. :-)


Figure 12 – specifying the AutoCAD commands to expose with the OEM Make Wizard

Now we add our custom module. Application modules need to be bound to a particular OEM product, if they are to be loaded by it. This is essentially where we tell AutoCAD OEM’s security layer to allow specific modules to be loaded. This step also lets us specify a location to copy the application module to. .NET modules don’t need to be built specially, while ObjectARX modules need to be built against a special version of the ObjectARX SDK.


Figure 13 – adding your own modules with the OEM Make Wizard

Then we need to specify the commands that our module implements – in our case it’s SD and SD2.


Figure 14 – exposing your commands with the OEM Make Wizard

To enable Automation to work from outside our application – especially to embed it as an ActiveX control, which we will do later – we need to assign GUIDs for a number of interfaces. This is handled automatically by the tool.


Figure 15 – defining an automation interface with the OEM Make Wizard

Next we customize the look & feel of our application, firstly by assigning a new splash screen, about box image and background image for our application frame.


Figure 16 – specifying custom splash screen and about box images with the OEM Make Wizard

We can also choose to disable certain user interface elements, such as toolbars and dashboards. This is clearly important to do if we’re disabling standard AutoCAD functionality.


Figure 17 – turning off user interface components with the OEM Make Wizard

The same applies for AutoCAD features – we can disable various parts of AutoCAD’s standard functionality from this page.


Figure 18 – turning off AutoCAD features with the OEM Make Wizard

Certain file associations used by AutoCAD are not relevant for our AutoCAD OEM application. DWG is needed, of course, but many others are not.


Figure 19 – turning off file associations with the OEM Make Wizard

Finally – before we build – we can change the standard application icons (for the frame, each document, etc.) to be more representative of our application look & feel.


Figure 20 – changing your application’s icons with the OEM Make Wizard

Now let’s build the application. This can be time-consuming, but the good news is that many changes do not require a full rebuild. You can decide which parts of the build should be rebuilt – deciding exactly which parts comes with experience, or you can always choose to perform a full rebuild, of course.


Figure 21 – building your application with the OEM Make Wizard


Figure 22 – our OEM Make Wizard build is complete

And here’s our running custom-branded OEM product:


Figure 23 – our running AutoCAD OEM product

Currently the custom .NET module that implements our SD and SD2 command can be loaded using the standard NETLOAD command inside our AutoCAD OEM product. To make life easier we’re now going to implement demand-loading. The attached Registry file, when merged, will cause our AutoCAD OEM product to load our custom module when either the SD or the SD2 command is invoked by the user:

Windows Registry Editor Version 5.00




"LOADER"="C:\\Program Files\\Autodesk\\AutoCAD OEM 2008\\oem\\Solids\\solidsanalyzer.dll"





The LOADCTRLS value above is “C” – hexadecimal for 12. This means that we’re saying the module will be loaded either “on load request” (8) or “on command invocation” (4). We could change this value to “2” (which is the same in decimal as in hexadecimal :-) if we wanted to load the module automatically “on startup”.

For more information on this topic, search for “demand loading” on the Through the Interface blog, or type in this URL:

Further streamlining the user interface by embedding our AutoCAD OEM product

For our final demonstration in this session, we’re going to embed the AutoCAD OEM product we’ve just built into a .NET application.

Just as we added the DWG Thumbnail and DWG TrueView control to our Visual Studio Toolbox, we can now add the ActiveX control for our solids-editing product.

Adding_the_autocad_oem_control_to_o Autocad_oem_control_in_our_toolbo_2  

Figure 24 - adding our AutoCAD OEM product’s control to your Visual Studio Toolbox

Once we’ve embedded the control in our form (MainForm), with buttons for browsing to a file (BrowseButton), analyzing the drawing (AnalyzeButton) and closing the application (CloseButton), we can add some code behind the buttons:

Public Class MainForm

  Private Sub BrowseDwgFile_Click _

    (ByVal sender As System.Object, _

    ByVal e As System.EventArgs) _

    Handles BrowseButton.Click

    Dim dlg As New System.Windows.Forms.OpenFileDialog()

    dlg.InitialDirectory = "c:\"

    dlg.Filter = "Dwg files (*.dwg)|*.dwg|All files (*.*)|*.*"

    If dlg.ShowDialog() = Windows.Forms.DialogResult.OK Then

      Dim oc As Cursor = Me.Cursor

      Me.Cursor = Cursors.WaitCursor



      AxAcCtrl1.Src = dlg.FileName

      Me.Cursor = oc

    End If

  End Sub

  Private Sub AnalyzeButton_Click _

    (ByVal sender As System.Object, _

    ByVal e As System.EventArgs) _

    Handles AnalyzeButton.Click

    If AxAcCtrl1.Src <> "" Then

      AxAcCtrl1.PostCommand("SD2 ")

    End If

  End Sub

  Private Sub CloseButton_Click _

    (ByVal sender As System.Object, _

    ByVal e As System.EventArgs) _

    Handles CloseButton.Click


  End Sub

End Class

When we run the code, we can use the “Load” button to load our DWG file:


Figure 25 – our AutoCAD OEM product embedded in a simple form

We can now launch our SD2 command using the “Analyze” button:


Figure 26 – the SD2 command running in our embedded AutoCAD OEM product

So ends the handout for my first AU session. The handout for the second session - which extends this session to focus on DWF, DWFx and Freewheel - will be posted next, starting later this week (all being well).


TrackBack URL for this entry:

Listed below are links to weblogs that reference AU Handouts: There's More to .DWG Than AutoCAD® - Part 3:

» More to CAD-Part3-Building a full editing product using AutoCAD OEM from
You've been kicked (a good thing) - Trackback from [Read More]

blog comments powered by Disqus


10 Random Posts