Fastest way to check if Thumbnail contains any graphics

Fastest way to check if Thumbnail contains any graphics

Maxim-CADman77
Advisor Advisor
848 Views
6 Replies
Message 1 of 7

Fastest way to check if Thumbnail contains any graphics

Maxim-CADman77
Advisor
Advisor

I need to compose iLogic (or VB) code for as-fast-as-possible check whether active document's Thumbnail is empty (has at least two pixels different in color). I guess it is not Inventor's special task yet don't know where to start from.  

AddReference "Stdole.dll"
Imports stdole

Sub Main
	Dim oThumb As stdole.IPictureDisp
	Dim NoThumb As Boolean=1
Try
	oThumb=ThisDoc.Document.Thumbnail 
	NoThumb=0
	' if ??? Then MsgBox("Doc's Thumb is empty")
Catch
   MsgBox ("Active DOc has no Thumb")
End Try

End Sub

Maybe there is some VB method otherwise I will compare each and every pixel with white which is supposed to be too long. Any help is appreciated.

Please vote for Inventor-Idea Text Search within Option Names

0 Likes
Accepted solutions (1)
849 Views
6 Replies
Replies (6)
Message 2 of 7

Maxim-CADman77
Advisor
Advisor

I'm attaching two samples (one with meaningful and second with empty thumbnail)

Please vote for Inventor-Idea Text Search within Option Names

0 Likes
Message 3 of 7

chandra.shekar.g
Autodesk Support
Autodesk Support

@Maxim-CADman77,

 

Both parts are empty. Can you please re check it again? Also specify Inventor version.

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 4 of 7

Maxim-CADman77
Advisor
Advisor

Yes - 3Dgeometry of both are empty. But one has a thumbnail embedded. Other has an empty thumbnail (which btw could be embedded as well In context of the tsak it doesn't matter if it is natural or embedded).

Those are testing samples for the task.

I'm using Inventor 2014 but I don't mind to get solution for some newer version (I suppose It would be applicable for 2014 as well).

 

Please vote for Inventor-Idea Text Search within Option Names

0 Likes
Message 5 of 7

clutsa
Collaborator
Collaborator

So I'm cheating and making assumptions but, is it possible to think that if the part has no volume and the user didn't set the thumbnail to an imported image that the preview will be blank?

AddReference "Stdole.dll"
Imports stdole

Sub Main
	Dim doc As Document = ThisApplication.ActiveDocument
	Dim oThumb As stdole.IPictureDisp
	Dim NoThumb As Boolean=1
Try
	oThumb=doc.Thumbnail 
	NoThumb=0
	If doc.ComponentDefinition.MassProperties.Volume = 0 Then 
		If Not doc.ThumbnailSaveOption = THumbnailSaveOptionEnum.kImportFromFile Then
			MsgBox("Doc's Thumb is empty")
		End If
	End If
Catch
   MsgBox ("Active DOc has no Thumb")
End Try
End Sub
If I've helped you, please help me by supporting this idea.
Mass Override for Each Model State

Custom Glyph Icon for iMates

Message 6 of 7

philip1009
Advisor
Advisor

Document.Thumbnail() As IPictureDisp is a read only property whose value is an IPictureDisp.

 

IPictureDisp is a Microsoft object so you'll need to learn some Microsoft SDK:

https://msdn.microsoft.com/en-us/library/windows/desktop/ms680762(v=vs.85).aspx

 

My understanding is iLogic can't import objects like this, I may be wrong there, feel free to share your results with us.  Otherwise you'll have to make the code in Visual Studio and develop the code as an Inventor Add-In.

0 Likes
Message 7 of 7

BrianEkins
Mentor
Mentor
Accepted solution

Both of the part files you originally attached contain a thumbnail image.  It's just one of them is visually empty because the entire image is a single color.  It is possible for a document not to have any thumbnail image at all.  I've attached an example.  In this case, calling the Thumbnail property fails.

 

In your case, you are getting back images, so you'll need to check the contents of the image to see if all of the pixels are the same color.  The underlying system that the Inventor API is based on (COM Automation) uses the IPictureDisp object to represent images.  If you're using VBA then it's relatively easy to work with.  However, if you're using a .NET based language (iLogic uses VB.NET) they don't natively support IPictureDisp so you'll either have to import and use Win32 functions or convert the IPictureDisp to a .NET image or bitmap and then use functions they provide to examine the contents of the image in more detail.  

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com