Accessing Thumbnail Images

I’ve had a few recent posts that have talked briefly about using thumbnail images (Document Thumbnails and Button Icons, Parts List with Thumbnail Image, and Accessing iProperties).  If you need to get a thumbnail image from an Inventor document there are several possibilities.  I want to briefly cover those here.

Thumbnail as an iProperty
The thumbnail is stored as an iProperty within an Inventor document.  One way to access the thumbnail is as an iProperty.  The following VBA code accesses the thumbnail as an iProperty and writes it as a bmp file to disk.  (This code won’t work on a 64-bit Inventor because of the issues discussed in this post.)

Public Sub WriteThumbnail()          ' Get the currently active document.              Dim doc As Document           Set doc = ThisApplication.ActiveDocument                 ' Get the Summary Information property set.              Dim summaryInfo As PropertySet           Set summaryInfo = doc.PropertySets.Item( _                                            "Inventor Summary Information")                 ' Get the thumbnail property.  When using VBA, this will              ' only work with 32-bit Inventor.               Dim thumbProp As Property           Set thumbProp = summaryInfo.Item("Thumbnail")                 ' Get the thumbnail image.              Dim thumbnail As IPictureDisp           Set thumbnail = thumbProp.Value                 ' Check that an image was returned.  It's possible for a              ' file to not have a thumbnail.               If Not thumbnail Is Nothing Then               ' Write the thumbnail to disk.                  Call SavePicture(thumbnail, "C:TempThumb.bmp")           Else               MsgBox "The active document doesn't have a thumbnail."           End If       End Sub

Because Apprentice provides access to iProperties, you can use it instead of Inventor to access the thumbnail.  Below is some VB.Net code that uses Apprentice to read a thumbnail from an Inventor document and display it within a picture box.

To use the code below, create a new “Windows Form Application”.  On the form add a button (Button1) and a picture box (PictureBox1).  Set the SizeMode property of the picture box to StretchImage.  My dialog is shown below.

ThumbnailDialogBefore

You’ll also need to add references to the following components using the .Net tab of the Add Reference dialog:

Autodesk.Inventor.Interop
Microsoft.VisualBasic.Compatibility
stdole

Here’s my implementation for the form and the button click sub.

Imports Inventor      Imports Microsoft.VisualBasic     Public Class Form1     Private Sub Button1_Click(ByVal sender As System.Object, _                       ByVal e As System.EventArgs) Handles Button1.Click        ' Create an instance of Apprentice.        Dim apprentice As New ApprenticeServerComponent                   ' Open a document.        Dim doc As ApprenticeServerDocument        doc = apprentice.Open("C:TempPart1.ipt")              ' Get the Summary Information property set.        Dim summaryInfo As PropertySet        summaryInfo = doc.PropertySets.Item( _                                           "Inventor Summary Information")              ' Get the thumbnail property.        Dim thumbProp As Inventor.Property        thumbProp = summaryInfo.Item("Thumbnail")              ' Get the thumbnail image.        Dim thumbnail As stdole.IPictureDisp        thumbnail = thumbProp.Value              ' Convert the IPictureDisp object to an Image.        Dim img As Image = _                           Compatibility.VB6.IPictureDispToImage(thumbnail)                   ' Display the image in the picture box.        PictureBox1.Image = img     End Sub       End Class

And here’s the result.
ThumbnailDialogAfter

Document.Thumbnail Property
There’s another way you can get the thumbnail that’s simpler than going through the iProperty objects.  Both the Document and ApprenticeServerDocument object
s  support the Thumbnail property.  Here’s a modified version of the program above that uses the Thumbnail property.

Imports Inventor      Imports Microsoft.VisualBasic     Public Class Form1     Private Sub Button1_Click(ByVal sender As System.Object, _                       ByVal e As System.EventArgs) Handles Button1.Click        ' Create an instance of Apprentice.        Dim apprentice As New ApprenticeServerComponent                   ' Open a document.        Dim doc As ApprenticeServerDocument        doc = apprentice.Open("C:TempPart1.ipt")               ' Get the thumbnail image.        Dim thumbnail As stdole.IPictureDisp        thumbnail = doc.Thumbnail                   ' Convert the IPictureDisp object to an Image.        Dim img As Image = _                           Compatibility.VB6.IPictureDispToImage(thumbnail)                   ' Display the image in the picture box.        PictureBox1.Image = img     End Sub       End Class

A big difference between using the Document.Thumbnail property and accessing the thumbnail as an iProperty is that the Document.Thumbnail property is read-only while the iProperty is writable.  This means you can push any image you would like into the iProperty to be used as the thumbnail for that document.  However, this is only supported in Inventor and setting the value of the thumbnail iProperty will fail when using Apprentice.

ThumbnailView Component
There’s one other way of accessing a thumbnail.  Because iProperties are stored using some Microsoft standards, it’s possible to use Windows functionality to directly access the thumbnail without using Inventor or Apprentice.  It requires some more advanced programming to do it this way, so to make it easier there’s a  component delivered as part of the Inventor SDK that you can use rather than write the code yourself.  The source code is also provided to serve as a sample for those that want to include this functionality within their applications.

To use this component you need to first install the DeveloperTools.msi package.  This is in the Inventor SDK directory (C:Program FilesAutodeskInventor 2011SDK on WinNT and C:UsersPublicDocumentsAutodeskInventor 2011SDK on Vista or Win7).  Installing this will create an SDKDeveloperToolsToolsThumbnailView directory that contains the component, its source code, and some samples demonstrating its use.

To use the component, go into the Bin directory and run the Register.bat file to register the component.  In your project where you’ll be using the component you’ll need to add a reference to it.  I typically use the Browse option and browse to the InventorThumbnailView.dll file.  Here’s a version of the previous program that uses this component to get the thumbnail.

Imports Microsoft.VisualBasic     Public Class Form1     Private Sub Button1_Click(ByVal sender As System.Object, _                       ByVal e As System.EventArgs) Handles Button1.Click        ' Create an instance of the ThumbnailProvider component.               Dim thumbView As New InventorThumbnailViewLib.ThumbnailProvider           ' Get the thumbnail image.        Dim thumbnail As stdole.IPictureDisp        thumbnail = thumbView.GetThumbnail("C:TempPart1.ipt")                  ' Convert the IPictureDisp object to an Image.        Dim img As Image = _                           Compatibility.VB6.IPictureDispToImage(thumbnail)                   ' Display the image in the picture box.        PictureBox1.Image = img     End Sub       End Class

One thing important to notice is that there’s no longer a reference to the Inventor component required since this isn’t using the Inventor API.

Inventor 2011 and ThumbnailView
The ThumbnailView component has been provided as a sample for several releases of Inventor.  However, an issue was discovered soon after Inventor 2011 was shipped where it was found the component doesn’t work with Inventor 2011 files.  In Inventor 2011 a change was made to how the thumbnail image is stored within the iProperty value.  Previously to Inventor 2011 it was stored as a bmp image.  In Inventor 2011 it’s now saved as a png image.  All of the other functionality that deals with the thumbnail, iProperties and the Document.Thumbnail property, were updated to account for this change.  However, the ThumbnailView utility slipped through the cracks and was not updated.  You can access an updated version of the component here that works with Inventor 2011 and previous files.


Comments

10 responses to “Accessing Thumbnail Images”

  1. Davide Avatar
    Davide

    Hi Brian,
    I’ve just tried updated version of thumbnailView for Inv2011 files but nothing seems to be changed. Could you check please?
    Thank you in advance

  2. Davide Avatar
    Davide

    Hi,
    sorry for my previous post. I installed directly InventorThumbnailView.dll found in Release directory. After, I’ve tried to rebuild project and I’ve installed resulting dll. This seems to be good. I hope this is helpful.
    Cheers

  3. Thank you for this information. I’ve rebuilt both the 32 and 64-bit versions of the dll and have repackaged the file.

  4. Brian,
    Does introducing PNG somehow connected with introducing ability to discard Inventor-user-chosen background when using thumbnails in Vault or something like this?

  5. As I understand IPTs, IAMs, IDWs etc now use PNG as thumbnail. But I see DWF still uses JPG :(

  6. InventorThumbnailView.dll
    I am having trouble running an application on Windows 7 x32 and x64 if it runs as administrator using the dll.
    I get the error “Could not obtain thumbnail provider….” when running your sample “ViewThumgnail”
    Works fine if it isn’t run as admin. My application needs admin.

  7. Scott K Avatar
    Scott K

    I have tested the code that you posted for exporting the sheet metal flat pattern and putting edges on specific layers. Do you know if the same can be done with sketch lines of an unconsumed sketch in the flat pattern?

  8. Hi Brian,
    First I want to thank you for making this post about Inventor 2011 thumbnail. It really helped out on my project.
    As what I do is a PDM-like software and is not free to my clients, is it against Autodesk. or the author using InventorThumbnailView.dll in my code?
    I have not include this DLL into my code yet, but it seems to be the easiest way to solve the Inventor 2011 preview issue.
    Also I had a lot of fun reading stuff here. Good site!

  9. Hi Brian
    I have download the ThumbnailViewer.dll
    Reg. the ThumbnailViewer.dll as admin.
    and it succeded.
    On win 7 64 bit. the dll file, do not show
    in the add reference list in my VB 2010
    it is seems that the dll file is not registered
    is there something wrong with the ThumbnailViewer.dll for 64 bit ?

  10. Jim Duncan Avatar
    Jim Duncan

    Brian,
    I have been reading some of your posts and have a challange for you.
    I have a macro that works in 2009 but doesn’t seem to work in 2012. The Macro takes a skeleton file and creates an Assembly file, all the derived parts for the assembly as their own ipt files, and then places all the parts into the assembly file. We are wanting to upgrade to 2012 and Windows 7 from 2009 and XP.
    I have a test machine set up with just windows 7 and 2012 on it. I can’t get the macro to work and don’t have an ideas why.
    Can you help? If you think you can I will send you the macros.

Leave a Reply

Discover more from Autodesk Developer Blog

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

Continue reading