Thumbnails.....

Thumbnails.....

NachoShaw
Advisor Advisor
4,171 Views
12 Replies
Message 1 of 13

Thumbnails.....

NachoShaw
Advisor
Advisor

Should it really that hard to try and convert an iProperty thumbnail into an actual image? Its pretty much like Inventor developers are still back in the early 90's with methods that nothing from this day and age can or will use....

 

Microsoft.compatibility = obselete

iPictureDispConverter = Cannot use because axhost has a crap load of issues attached to it that just don't allow you to build

PictureDispConverter only converts to an iPictureDisp

 

pretty much any other method around doesn't work

 

Nacho
Automation & Design Engineer

Inventor automation Programmer (C#, VB.Net / iLogic)
Furniture, Sheet Metal, Structural, Metal fab, Tradeshow, Fabrication, CNC

EESignature


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.


0 Likes
4,172 Views
12 Replies
Replies (12)
Message 2 of 13

MechMachineMan
Advisor
Advisor

Add a reference to "OLE Automation" to use stdole.

 

Sub Main()
Dim Thumbnail As IPictureDisp Set Thumbnail = oDoc.PropertySets.Item("Inventor Summary Information").Item("Thumbnail").Value Call CreateThumbnail(Thumbnail, oThumbcol, oRow) Set Thumbnail = Nothing End Sub


Public Sub CreateThumbnail(Thumbnail As IPictureDisp, oColumn As Integer, ByVal CellRowNum As Integer) 'Changed to put N/A in same column as comments. if there is an error, check this first. On Error GoTo Handler Call stdole.SavePicture(Thumbnail, "C:\Temp\Thumb.jpg") Handler: If Err.Number = 380 Then ws.Cells(CellRowNum, oColumn).Value = "N/A" Exit Sub End If With ws.Cells(CellRowNum, oColumn) .AddComment .Comment.Visible = False .Comment.Shape.Fill.UserPicture ("C:\Temp\Thumb.jpg") .Comment.Shape.Height = 75 .Comment.Shape.Width = 75 End With End Sub

 


--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
0 Likes
Message 3 of 13

NachoShaw
Advisor
Advisor

Hi

 

Thanks for the reply. Does that solution work through VB.Net? I cant find any reference available that is or is similar to OLE automation

 

 

Cheers

 

Nacho

Nacho
Automation & Design Engineer

Inventor automation Programmer (C#, VB.Net / iLogic)
Furniture, Sheet Metal, Structural, Metal fab, Tradeshow, Fabrication, CNC

EESignature


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.


0 Likes
Message 4 of 13

MechMachineMan
Advisor
Advisor
No. Just through vba as in excel. AFAIK, 64 bit windows utilizing vb.net
requires some interesting programing to make it work as it seems you have
discovered.

--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
0 Likes
Message 5 of 13

NachoShaw
Advisor
Advisor

Well...... I have it working on 64bit using Microsoft.VisualBasic.Compatibility.VB6 which is the obsolete method however, its the ONLY one that works....

 

AxHost - just crashes my PC

iPictureDispConverter - crashes Visual Studio

 

Apart from the now obsolete method, is there any other method? what was the Framework 4.5 equivalent to the framework 3 compatibility method? Seens there is nothing that comes close.

 

 

Nacho

Nacho
Automation & Design Engineer

Inventor automation Programmer (C#, VB.Net / iLogic)
Furniture, Sheet Metal, Structural, Metal fab, Tradeshow, Fabrication, CNC

EESignature


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.


0 Likes
Message 6 of 13

ekinsb
Alumni
Alumni

Here's some test code I put together in a Visual Basic exe that is working.  It uses apprentice to extract a thumbnail from a document and then saves it back out as a png file, converting it from an IPictureDisp object to an Image in the process.  This should also work in an add-in.  This example won't work if it tries to connect to Inventor because Inventor and this program will be running in separate processes and COM doesn't support passing an IPictureDisp object between processes.

 

Imports Inventor
Imports System.Runtime.InteropServices

Public Class Form1
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim apprentice = New Inventor.ApprenticeServerComponent
        Dim doc As Inventor.ApprenticeServerDocument = apprentice.Open("C:\Temp\Part1.ipt")

        Dim picDispThumb As stdole.IPictureDisp = doc.Thumbnail
        Dim imageThumb As Image = AxHostConverter.PictureDispToImage(picDispThumb)
        imageThumb.Save("C:\Temp\testThumb.png")
    End Sub
End Class

Public Module Utilities
    Friend Class AxHostConverter
        Inherits AxHost
        Private Sub New()
            MyBase.New(GetType(stdole.IPictureDisp).GUID.ToString)
        End Sub

        Public Shared Function PictureDispToImage(pictureDisp As stdole.IPictureDisp) As Image
            Return GetPictureFromIPicture(pictureDisp)
        End Function

        Public Shared Function ImageToPictureDisp(image As Image) As stdole.IPictureDisp
            Return DirectCast(GetIPictureDispFromPicture(image), stdole.IPictureDisp)
        End Function
    End Class
End Module

 

 


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
0 Likes
Message 7 of 13

NachoShaw
Advisor
Advisor

Hi Brian

 

Appreciate the reply and effort. I had been using Apprentice as I was aware of the Inventor issues. Odd though, Whenever I use anything that has a reference to AxHost, I get an error message stating that AxHost cannot be used because it is abstract which is shortly followed by an Inventor crash, a visual Studio crash and ultimately, a complete blue screen PC crash..

 

I will however try the code you have posted and see if I get the same behaviour 🙂

 

 

Thanks again

 

 

Nacho

Nacho
Automation & Design Engineer

Inventor automation Programmer (C#, VB.Net / iLogic)
Furniture, Sheet Metal, Structural, Metal fab, Tradeshow, Fabrication, CNC

EESignature


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.


0 Likes
Message 8 of 13

NachoShaw
Advisor
Advisor

Hi Brian

 

UPDATE

 

Are you saying then that if Inventor was already open and I used the supplied code (even though the code exclusively uses Apprentice only), it wont work? I have tried the code this evening and I get an error:

 

AxHost.png

 

And here is the full error

 

See the end of this message for details on invoking 
just-in-time (JIT) debugging instead of this dialog box.

************** Exception Text **************
System.NotImplementedException: Not implemented (Exception from HRESULT: 0x80004001 (E_NOTIMPL))
   at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)
   at Inventor.ApprenticeServerDocument.get_Thumbnail()
   at oSheets.pAssyStructure.LoadImage(String sPath) in C:\Users\Nige\Documents\Visual Studio Projects\Inventor\oSheets\oSheets\Pages\pAssyStructure.vb:line 110
   at oSheets.pAssyStructure.GridControl1_Click(Object sender, EventArgs e) in C:\Users\Nige\Documents\Visual Studio Projects\Inventor\oSheets\oSheets\Pages\pAssyStructure.vb:line 100
   at System.Windows.Forms.Control.OnClick(EventArgs e)
   at DevExpress.XtraGrid.GridControl.OnClick(EventArgs ev)
   at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at DevExpress.XtraEditors.Container.EditorContainer.WndProc(Message& m)
   at DevExpress.XtraGrid.GridControl.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

So, I added this to my click Event

Dim apprentice = New Inventor.ApprenticeServerComponent
        Dim doc As Inventor.ApprenticeServerDocument = apprentice.Open(sPath)

        Dim picDispThumb As stdole.IPictureDisp = doc.Thumbnail
        Dim imageThumb As Image = AxHostConverter.PictureDispToImage(picDispThumb)

I then added this after the form Class

Public Module Utilities
    Friend Class AxHostConverter
        Inherits AxHost
        Private Sub New()
            MyBase.New(GetType(stdole.IPictureDisp).GUID.ToString)
        End Sub

        Public Shared Function PictureDispToImage(pictureDisp As stdole.IPictureDisp) As Image
            Return GetPictureFromIPicture(pictureDisp)
        End Function

        Public Shared Function ImageToPictureDisp(image As Image) As stdole.IPictureDisp
            Return DirectCast(GetIPictureDispFromPicture(image), stdole.IPictureDisp)
        End Function
    End Class
End Module

I also tried in a separate Module and also a Class all of which, gave me the same error

 

 

 

Thanks

 

Nacho

Nacho
Automation & Design Engineer

Inventor automation Programmer (C#, VB.Net / iLogic)
Furniture, Sheet Metal, Structural, Metal fab, Tradeshow, Fabrication, CNC

EESignature


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.


0 Likes
Message 9 of 13

ekinsb
Alumni
Alumni

I've attached my complete project, which is working for me.  It also contains another class that I had found a few years ago for converting between .NET images and IPictureDisp but I'm not using it here.

 

If you're using Apprentice, it should always work, as long as Apprentice can access and open the file.  What won't work is if you write an EXE that is trying to get the thumbnail from Inventor.  It's not possible to pass an image from one process (Inventor in this case) to another (your EXE).  An add-in will work because it's running within the Inventor process.


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
0 Likes
Message 10 of 13

NachoShaw
Advisor
Advisor

Hi Brian

 

Thanks for the update. I am not making an EXE, I am working on an Addin. So,

 

My Addin loads with Inventor

I load a New Instance of my form

when  click an item in the list I generate, I want to get the thumbnail of that item.

I am saving the full path in the list and using the path with Apprentice to open in silently and get the thumbnail

 

Theoretically, this process is NOT using the Inventor connection directly to access the file, it is using Apprentice

 

 

Thanks

 

Nigel

 

Nacho
Automation & Design Engineer

Inventor automation Programmer (C#, VB.Net / iLogic)
Furniture, Sheet Metal, Structural, Metal fab, Tradeshow, Fabrication, CNC

EESignature


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.


0 Likes
Message 11 of 13

ekinsb
Alumni
Alumni

You can't use Apprentice from within an add-in.  This isn't related to the IPictureDisp issue I explained before but is a limitation of Inventor.  Apprentice and Inventor use many of the DLL's so when you try to load Apprentice into Inventor there are problems.  You'll need to open the file in Inventor and then you should be able to use the Thumbnail property.


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
0 Likes
Message 12 of 13

frederic.vandenplas
Collaborator
Collaborator

Hi,

 

It's an old post, but i stumbled upon the same problems, and none of the provided code/suggestions helped me until i found this one

 

http://www.c3mcad.com/ProductPages/MiscTools/ProductIvThumbs.aspx

 

To simple lines of code and a reference to a dll

 

Great solution for me, and hopefully for other people too!

If you think this answer fullfilled your needs, improved your knowledge or leads to a solution,
please feel free to "kudos"
Message 13 of 13

lukasz.klonica
Explorer
Explorer

I know this is an old post, but I was also looking for a solution to this problem and in my case (Inventor add-in dll and Inventor 64bit) I use WindowsAPICodePack. The thumbnail is obtained directly from the file, not the Inventor document.

 

 

Dim shFile As Microsoft.WindowsAPICodePack.Shell.ShellFile = Microsoft.WindowsAPICodePack.Shell.ShellFile.FromFilePath(doc.FullFileName)
Dim shFileBitmap As Bitmap = shFile.Thumbnail.Bitmap
Dim shFileLargeBitmap As Bitmap = shFile.Thumbnail.ExtraLargeBitmap

 

 

It is used in the .dll library and does not cause problems even with the BackgroundWorker.RunWorkerAsync () thread. In addition, it allows you to receive thumbnails and icons of other file formats.

 

This can also be helpful:

https://stackoverflow.com/questions/1439719/c-sharp-get-thumbnail-from-file-via-windows-api 

 

Size of Thumbnail (Width/Height)

Bitmap 256 / 256
ExtraLargeBitmap 1024 / 1024
LargeBitmap 256 / 256
MediumBitmap 96 / 96
SmallBitmap 32 / 32

0 Likes