November 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            










« AU Handouts: There's More to .DWG Than AutoCAD® - Part 1 | Main | AU Handouts: There's More to .DWG Than AutoCAD® - Part 3 »

October 22, 2007

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

[This post continues from the last post, which I've been back and modified slightly since it was posted.]

Using the DWG Thumbnail in a simple application

Thumbnail images, when they exist inside a drawing, live in a predictable place at the beginning of the file. This makes it possible for a module – such as an ActiveX control – to extract the thumbnail information when pointed at a DWG file and generate an image from it. All done without the need for RealDWG (which also does this, but with a much heavier runtime component).

A number of 3rd party tools are available to do this – I’d suggest searching on Google – and our team provides one to ADN members, along with a number of other ActiveX controls for display of layers, linetypes, hatch patterns, slides, etc. etc.:

http://adn.autodesk.com/adn/servlet/item?siteID=4814862&id=9628824&linkID=4900509

To make use of the DWG Thumbnail control in your application, you need to add it to your Visual Studio Toolbox, by right-clicking on it, selecting “Choose Items…” and using the COM Components tab to browse to the DwgThumbnail.ocx file. On my system the file is under “C:\Program Files\Autodesk\ADN AutoCAD Utilities\Utilities\AutoCAD Controls”.

Dwg_thumbnail_adding_to_toolbox Dwg_thumbnail_in_toolbox

Figure 7 – adding the DWG Thumbnail control to your Visual Studio Toolbox

Now you can add control to your form and implement some logic to set the DwgFileName property to the location of your DWG file.

Embedding DWG TrueView in an HTML page or dialog

DWG TrueView can be embedded in an HTML page or dialog and controlled via its COM Automation interface, whether from HTML scripting (JavaScript, VBScript) or another choice of scripting language, if embedded in a dialog. There is a large caveat: this is not a fully supported mode of working with DWG TrueView, so don’t have very high hopes. Simple embedding should work, but if you’re trying to do anything more complex you’re likely to run into problems.

Here’s an HTML fragment, which shows how to embed the DWG TrueView ActiveX control:

[from https://projectpoint.buzzsaw.com/constructionmanagement/public/testDWG.htm?public]

<object

  id="dwgViewerCtrl"

  classid="clsid:6C7DC044-FB1E-4140-9223-052E5ABE7D24"

  height="100%"

  width="100%"

  data="DATA:application/x-oleobject;BASE64,RMB9bB77QEGSIwUuWr59JAAHAAARTAAArjAAAA==

">

</object>

It’s also straightforward to embed DWG TrueView in your .NET application, just like the DWG Thumbnail control: from your Visual Studio Toolbox, right-click and select “Choose Items…”, selecting the “COM Components” tab and then the “DWGVIEWRCtrl” item from the list of controls:

Trueview_to_toolbox Trueview_in_toolbox

Figure 8 – adding the DWG TrueView control to your Visual Studio Toolbox

Now you simply need to add it to your form, and add some logic to select the filename to pass into the PutSourcePath() method of the control (either via a browse button, a text box or a hard-coded path).

To compare the capabilities of these two controls, we’re now going to build a simple application that embeds the DWG Thumbnail control alongside DWG TrueView.

After adding the controls to our Toolbox, we design a simple form (ComparisonForm), with a single button to “Load” a DWG file (LoadButton). This button browses for a DWG and loads it into the DWG Thumbnail control and into DWG TrueView.

Here’s the code:

Public Class ComparisonForm


  Private Sub LoadButton_Click _

    (ByVal sender As System.Object, _

    ByVal e As System.EventArgs) _

    Handles LoadButton.Click

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

    dlg.InitialDirectory = _

      System.Environment.CurrentDirectory

    dlg.Filter = _

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


    Dim oc As Cursor = Me.Cursor

    Dim fn As String = ""


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

      Me.Cursor = Cursors.WaitCursor

      fn = dlg.FileName()

      Me.Refresh()

    End If


    If fn <> "" Then

      Me.AxDwgThumbnail1.DwgFileName = fn

      Me.AxDwgThumbnail1.Refresh()

      Me.AxAcCtrl1.PutSourcePath(fn)

    End If

    Me.Cursor = oc


  End Sub

End Class

When we run the application and select our DWG, we see it loaded into both controls (the Thumbnail loads almost instantaneously, the DWG file takes longer to load into DWG TrueView, of course, as DWG TrueView also needs to be instantiated behind the scenes):

Dwg_thumbnail_and_trueview

Figure 9 – embedding the DWG Thumbnail control alongside DWG TrueView

TrackBack

TrackBack URL for this entry:
http://www.typepad.com/services/trackback/6a00d83452464869e200e54efc28948833

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

» More to CAD-Part2-Using the DWG Thumbnail in a simple application from CadKicks.com
You've been kicked (a good thing) - Trackback from CadKicks.com [Read More]

blog comments powered by Disqus

Feed/Share

10 Random Posts