Getting thumbnail from Active Document to show in PictureBox VB.Net

Getting thumbnail from Active Document to show in PictureBox VB.Net

Anonymous
Not applicable
1,567 Views
3 Replies
Message 1 of 4

Getting thumbnail from Active Document to show in PictureBox VB.Net

Anonymous
Not applicable

I'm trying to get the thumbnail to show in a picture box.

I did some research and found this code from the Mod Machine guys, but i'm getting an error. System.Runtime.InteropServices.COMException: 'Catastrophic failure (Exception from HRESULT: 0x8000FFFF (E_UNEXPECTED))' on this line of code "thumbnail = thumbProp.value"

 

Sample Code

Public Sub WriteThumbnail()
        Dim oDoc3 As Document
        oDoc3 = ThisApplication.ActiveDocument
        Dim oPropSet3 As PropertySet
        oPropSet3 = oDoc3.PropertySets.Item("Inventor Summary Information")
    
        Dim thumbProp As Inventor.Property = oPropSet3.Item("Thumbnail")

        Dim thumbnail As stdole.IPictureDisp
        thumbnail = thumbProp.value 'Error Here

        Try
            PictureBox4.Image = thumbnail
        Catch ex As Exception
        End Try
    End Sub
0 Likes
Accepted solutions (2)
1,568 Views
3 Replies
Replies (3)
Message 2 of 4

Jef_E
Collaborator
Collaborator
Accepted solution

Try it like this

 

 

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:\Temp\Part1.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

Code source from this blog post

http://modthemachine.typepad.com/my_weblog/2010/06/accessing-thumbnail-images.html



Please kudo if this post was helpfull
Please accept as solution if your problem was solved

Inventor 2014 SP2
Message 3 of 4

Anonymous
Not applicable

It says this line of code is obsolete

 

Dim img As Image = Compatibility.VB6.IPictureDispToImage(thumbnail)

0 Likes
Message 4 of 4

Anonymous
Not applicable
Accepted solution

I just had to change my framework to 4 and it worked.

 

Thanks