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

Oem_make_wizard_begin_session

Figure 10 – starting a project with the OEM Make Wizard

On the next page we specify some additional information, such as a longer product name and version numbers. We also need to enter a keycode, taking the form MMSSSSSDD, where MM is the current month, SSSSS is the last 5 digits of your AutoCAD OEM serial number, and DD is the current day.

Oem_make_wizard_project_information

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. :-)

Oem_make_wizard_autocad_commands

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.

Oem_make_wizard_your_modules_2

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.

Oem_make_wizard_your_commands

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.

Oem_make_wizard_automation

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.

Oem_make_wizard_custom_images

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.

Oem_make_wizard_toolbar_and_dashboa

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.

Oem_make_wizard_autocad_features

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.

Oem_make_wizard_file_extensions

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.

Oem_make_wizard_change_icons

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.

Oem_make_wizard_build

Figure 21 – building your application with the OEM Make Wizard

Oem_make_wizard_build_complete

Figure 22 – our OEM Make Wizard build is complete

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

Autocad_oem_application

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


[HKEY_LOCAL_MACHINE\SOFTWARE\Autodesk\SolidsSystem\R11\SOLIDS-6001:409\Applications\SolidsAnalyzer]

"DESCRIPTION"="SolidsAnalyzer"

"LOADCTRLS"=dword:0000000c

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

"MANAGED"=dword:00000001


[HKEY_LOCAL_MACHINE\SOFTWARE\Autodesk\SolidsSystem\R11\SOLIDS-6001:409\Applications\SolidsAnalyzer\Commands]

"sd"="sd"

"sd2"="sd2"

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:

http://through-the-interface.typepad.com/through_the_interface/2006/09/automatic_loadi.html

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 BrowseDwgFile.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

      Me.Refresh()

      AxAcCtrl1.Focus()

      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

    Close()

  End Sub


End Class

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

Autocad_oem_embedded_application

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

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

Autocad_oem_embedded_application_an

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

October 24, 2007 in AutoCAD, AutoCAD .NET, AutoCAD OEM, Training | Permalink | Comments (1) | TrackBack

Recorded presentation on Autodesk's Component Technologies

It's been quite a week... I was attending Autodesk's annual One Team Conference in Las Vegas, and had a number of meetings before, during and afterwards (hence my inability to make any posts whatsoever since Sunday). It was hectic, but a great event - the highlight for me was the keynote address on Wednesday by none other that Bill Clinton, the 42nd President of the United States! Wow.

Anyway, late last week it came to my attention that a presentation of mine had made it onto one of Autodesk's public websites. Thanks to posts on Jimmy Bergmark's and Scott Sheppard's blogs for bringing it to my attention (I knew it was happening, I just didn't know when).

It's actually another in the series of presentations I mentioned in this previous post. The material is quite condensed - the whole presentation lasts just over 20 minutes, including a number of demos. Those of you I haven't met in person might find it interesting, just to find out what my voice sounds like (aside from the interesting content, that is! :-).

March 12, 2007 in AutoCAD, AutoCAD .NET, AutoCAD OEM, DWF, RealDWG | Permalink | Comments (2) | TrackBack

Webcast in the making

I thought I’d mention one of the projects we’re working on in DevTech right now. We’re planning a webcast for later this year, to talk our developers through the various technologies Autodesk provides to create/access/view native DWG data and published DWF data.

Here’s the idea: we show the generation of native DWG data using AutoCAD 2007 (in this case creating a number of 3D solids). We then take show how various technologies can be used to make use of the information stored in the native DWG file. Afterwards, we’ll publish the data to DWF – showing the capacity to add custom metadata using AutoCAD’s DWF Metadata API – and then show the various technologies that can be used to access and view the published DWF data.

Here's a quick description of some of the sample applications we're building to demonstrate the various technologies.

Native DWG

  1. A RealDWG application that accesses the DWG to extract the volume information of the contained 3D solids, displaying the results in a table (but not working with the geometry of the model at all).
    • Although a fairly basic sample, it demonstrates that precise analysis can be performed directly on the DWG contents without the need for a graphical display. It also shows how to make use of the .NET API to RealDWG.
  2. An application with DWG TrueView embedded, to show the basic capabilities of the use of this component.
    • This sample will show to what extent it is possible to embed this control for basic DWG display (without any further analysis of the DWG contents).
  3. An enhanced viewing application based on AutoCAD OEM, showing how this can look like a traditional CAD application or be embedded in another window.
    • This sample will show how it is possible to make use of AutoCAD's APIs within an enhanced viewing application. We'll be able to take the same .NET code from the RealDWG sample and show it working with an embedded viewer.

Published DWF

  1. A DWF Toolkit application that access the DWF, extracting metadata about the materials used in the model and displaying a non-graphical summary of this data.
    • In a similar way to the RealDWG sample, this one looks at how it is possible to use a file access toolkit to get at the contents of DWF files. While RealDWG focuses on the precise data representing the model, the DWF toolkit allows us to get at the published graphics and metadata. In this case we'll extract material metadata we attached during the publishing process using AutoCAD's APIs.
  2. Applications with the DWF Viewer embedded, showing how it can be used to create both simple and complex viewing applications.
    • This sample will show some of the cool stuff you can do with an embedded DWF Viewer - particularly around object selection events and the ability to visually isolate subsets of the graphics published out to the DWF file.

June 23, 2006 in AutoCAD, AutoCAD OEM, DWF, RealDWG | Permalink | Comments (0) | TrackBack