VBA Thumbnail iProperty Yields varying quality, file size, and back color

VBA Thumbnail iProperty Yields varying quality, file size, and back color

rcolon9E4ZX
Advocate Advocate
2,122 Views
15 Replies
Message 1 of 16

VBA Thumbnail iProperty Yields varying quality, file size, and back color

rcolon9E4ZX
Advocate
Advocate

Hello,

 

I am trying to collect thumbnails from the Thumbnail iProperty of a document, since this approach is very fast. The stored thumbnail is always 213x213pixels. Sometimes the resolution is great, and sometimes it is very poor. See image below. Not only that, the good resolution images have a dark gray background for some reason and the low res ones have the default. The file size for the good images is 769KB, which is the same size as a 512x512pixel bitmap from Camera.SaveAsBitmap. The low res files are <100KB.

 

Quality and back colorQuality and back color

 

Here is a snippet of VBA code run from Inventor where I acquire the image.

Dim summaryInfo As PropertySet
Dim thumbprop As Property
Dim thumbNail As IPictureDisp
Set summaryInfo = doc.PropertySets.Item("Inventor Summary Information")
Set thumbprop = summaryInfo.Item("Thumbnail")
Set thumbNail = thumbprop.Value 'Get the thumbnail image.
If Not thumbNail Is Nothing Then 'Check that an image was returned.  It's possible for a file to not have a thumbnail.
    ' Write the thumbnail to disk. Size is 213x213. Even if a larger image is imported. Overwrites existing file.
    Call stdole.StdFunctions.SavePicture(thumbNail, strFile)
Else
    'MsgBox "The active document doesn't have a thumbnail."
End If

 

Any ideas for what is causing this difference in results? Maybe some property in the document? One hypothesis I had, although disproved, is if the Master view rep was the only view rep for the document. Is there something else that is causing this? This seems very odd to me.

 

Many thanks in advance.

Rafael

0 Likes
2,123 Views
15 Replies
Replies (15)
Message 2 of 16

rcolon9E4ZX
Advocate
Advocate

I am running on Win10 Inv Pro 2019 x64 Build 330. Surely someone has seen or questioned this behavior before. The thumbnails appear in this fashion within Manage > Bill of Materials in Inventor. All of my files are set the same under the Save tab in iProperties. They are all from the same template. And yet, they store differently on save.

 

iProperties > SaveiProperties > Save

 

0 Likes
Message 3 of 16

rcolon9E4ZX
Advocate
Advocate

Can someone else confirm this behavior?

0 Likes
Message 4 of 16

Curtis_Waguespack
Consultant
Consultant

Hi @rcolon9E4ZX 

 

Due to time, I didn't really look too closely at what you posted other than the problem statement of the original post... but I think this link might offer a solution

 

https://forums.autodesk.com/t5/inventor-forum/is-there-a-way-to-refresh-all-thumbnails/m-p/7239233#M...

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

EESignature

0 Likes
Message 5 of 16

Curtis_Waguespack
Consultant
Consultant

Hi @rcolon9E4ZX .

 

I looked back at this and realized that something like this might be more what you are after, this version will write out an image file for the top level and  each component of an assembly.

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

 

Sub main 
	
oFolder = "C:\Temp\ThumbNails\"

Dim oDoc As Document
oDoc = ThisApplication.ActiveDocument

'get current color scheme name 
oColorScheme = ThisApplication.ActiveColorScheme.Name

'get current color scheme background type
oBackGroundType = ThisApplication.ColorSchemes.BackgroundType

'Change to Presentation (white background)
ThisApplication.ColorSchemes.Item("Presentation").Activate

'set to use one color background type
ThisApplication.ColorSchemes.BackgroundType = _
BackgroundTypeEnum.kOneColorBackgroundType 

Dim oAsmDoc As AssemblyDocument
oAsmDoc = ThisApplication.ActiveDocument

Dim oRefFile As FileDescriptor

	If oAsmDoc.AllReferencedDocuments.Count > 12 Then
		oRUSure = MessageBox.Show("This could take a while, continue?", "iLogic",MessageBoxButtons.YesNo)

		If oRUSure = vbNo Then
			Return 'exit rule
		End If
	End If

'save image for top level assembly
Call SaveImage(oDoc, oFolder)

For Each oDoc In oAsmDoc.AllReferencedDocuments	

	ThisApplication.Documents.Open(oDoc.FullFileName, True)  
	
	For Each oSketch In oDoc.ComponentDefinition​.Sketches
		oSketch.Visible = False
	Next
	
	'set work plane visibility
	For Each oWorkPlane In oDoc.ComponentDefinition.WorkPlanes
	oWorkPlane.Visible = False
	Next
	
	'set work axis visibility
	For Each oWorkAxis In oDoc.ComponentDefinition.WorkAxes
	oWorkAxis.Visible = False
	Next
	
	'set work point visibility
	For Each oWorkPoint In oDoc.ComponentDefinition.WorkPoints
	oWorkPoint.Visible = False
	Next

	
	Call SaveImage(oDoc, oFolder)
	oDoc.Close

Next

'Change back to original scheme
ThisApplication.ColorSchemes.Item(oColorScheme).Activate 

'Change back to original back ground type
ThisApplication.ColorSchemes.BackgroundType = oBackGroundType


Process.Start(oFolder) 

End Sub


Function SaveImage (oDoc As Document, oFolder As String)


	Dim m_Camera As Inventor.Camera
	Dim m_TO As Inventor.TransientObjects 

	m_TO = ThisApplication.TransientObjects
	m_Camera = ThisApplication.ActiveView.Camera
	'm_Camera.Perspective = True


	m_Camera.ViewOrientationType = Inventor.ViewOrientationTypeEnum.kIsoTopLeftViewOrientation
	m_Camera.Fit
	m_Camera.ApplyWithoutTransition


	Dim m_CV As Inventor.View
	m_CV = ThisApplication.ActiveView


	Dim m_PrevMode As Integer
	Dim m_Disp3D As Boolean


	m_PrevMode = m_CV.DisplayMode
	m_Disp3D = ThisApplication.DisplayOptions.Show3DIndicator


	m_CV.DisplayMode = Inventor.DisplayModeEnum.kShadedWithEdgesRendering
	ThisApplication.DisplayOptions.Show3DIndicator = False
	m_CV.Update

	'split the string into an array using the dash
	sMyArray = oDoc.FullFileName.Split("\")
	i = UBound(sMyArray)
	oFileName = sMyArray(i)
	
	
	sMyArray = oFileName.Split(".")
	oFileName = sMyArray(0)
	
	If Not System.IO.Directory.Exists(oFolder ) Then 
  	  System.IO.Directory.CreateDirectory(oFolder )
	End If
	
	'save image
	m_Camera.SaveAsBitmap( oFolder & oFileName &".bmp", 800, 600,)

End Function

 

EESignature

0 Likes
Message 6 of 16

rcolon9E4ZX
Advocate
Advocate

Curtis,

 

Thank you for your replies. I already do something similar to this with Camera.SaveAsBitmap. I like the default background as the thumbnail background stored in the ipt file. Do you see the dark gray gradient background in my original post, and how this image has better quality? Both images in this post are stored thumbnails for ipt files. I want to know what is making some thumbnails have this dark gray background and increased quality. This is just something Inventor is doing because I have not set any properties to make this happen. Best case, I get some way to control this outcome.

 

For your first reply, I ran this code in VBA. It is essentially your posted sample code, but I do not change the color scheme.

 

Sub RefreshThumbnails()

Dim oAsmDoc As AssemblyDocument
Set oAsmDoc = ThisApplication.ActiveDocument
Dim oDoc As Document

For Each oDoc In oAsmDoc.AllReferencedDocuments
    ' open document
    ThisApplication.Documents.Open oDoc.FullFileName, True
    
    For Each oSketch In oDoc.ComponentDefinition.Sketches
        oSketch.Visible = False
    Next
    
    'set work plane visibility
    For Each oWorkPlane In oDoc.ComponentDefinition.WorkPlanes
    oWorkPlane.Visible = False
    Next
    
    'set work axis visibility
    For Each oWorkAxis In oDoc.ComponentDefinition.WorkAxes
    oWorkAxis.Visible = False
    Next
    
    'set work point visibility
    For Each oWorkPoint In oDoc.ComponentDefinition.WorkPoints
    oWorkPoint.Visible = False
    Next

    'set iproperty to use ISO view on save
    oDoc.SetThumbnailSaveOption _
    (ThumbnailSaveOptionEnum.kActiveComponentIsoViewOnSave)
    
    'save and close the file
    oDoc.Save
    oDoc.Close
Next
End Sub

 

The two images below from left to right are before and after running the code, respectively.

Before CodeBefore Code After CodeAfter Code

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

You can see that all the thumbs now have the default background. They also have reduced quality compared to those that had the dark gray background, like in my original post. At the very least, this is a way to force the same results across all images, so thank you for the reference.

 

This dark gray background anomaly has had me stumped since I first started this utility four years ago. It would be great if you can find out what is causing this, and I would gladly accept as solution.

 

Regards.

Rafael

0 Likes
Message 7 of 16

rcolon9E4ZX
Advocate
Advocate

Should have used @Curtis_Waguespack in the last post.

0 Likes
Message 8 of 16

Curtis_Waguespack
Consultant
Consultant

Hi @rcolon9E4ZX ,

 

I'm not sure why you'd see a different background, but the example I posted here shows how to get and set the color scheme to control this... it looks like the dark gray gradient is likely the "Presentation" scheme.

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

EESignature

0 Likes
Message 9 of 16

rcolon9E4ZX
Advocate
Advocate

Hi @Curtis_Waguespack ,

 

The dark gray background appears to be the default color scheme "Winter Night", but with the background type set to Gradient instead of 1 Color or Background Image. See image below.

"Winter Night" > Gradient"Winter Night" > Gradient

So now we know what properties are being changed. For some reason, capturing the thumbnail on save utilizes background type Gradient, but only some of the time. Maybe this be for items that are saved in the context of an assembly?

 

Rafael

0 Likes
Message 10 of 16

Curtis_Waguespack
Consultant
Consultant

Hi @rcolon9E4ZX 

 

The code to use presentation and gradient is as follows, this would be per the application not per the file. 

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

 

 

'Change to Presentation 
ThisApplication.ColorSchemes.Item("Presentation").Activate

'set to use gradient color background type
ThisApplication.ColorSchemes.BackgroundType = _
BackgroundTypeEnum.kGradientBackgroundType 


 

EESignature

0 Likes
Message 11 of 16

rcolon9E4ZX
Advocate
Advocate

Hi @Curtis_Waguespack ,

 

I appreciate your replies. The only thing I am looking for in this thread is the root cause of why some thumbnails have the dark gray background along with increased quality. I now know the background type is changed to Gradient in some instances of saving thumbnail on save. I want to know why this is happening. Maybe this is some unintended result that can be corrected. Although untested, some hypotheses of mine are this happens when saving from context of an assembly, or it has something to do with Vault check-in or generating a DWF on check-in. Now that the change in properties is specifically understood, maybe someone knows where this takes place and why?

 

Regards.

Rafael

0 Likes
Message 12 of 16

Curtis_Waguespack
Consultant
Consultant

Hi @rcolon9E4ZX 

 

As mentioned the color scheme can be set per application, not per file... (edit to add: but since the thumbnail is not getting set ) I suspect maybe your code it not hitting the correct files as it processes the assembly, or it is catching an error and skipping certain files, or something similar... But unless I've missed it, you've not included your entire code here so it's impossible to say for sure.  

 

Does your VBA code include an "On Error Resume Next" line? If so, does commenting that out show you an error that might explain why some thumbnails are not getting updated?

 

Using the last code you posted and the last code I posted together I can change all of the thumbnail backgrounds to a given theme/color.

 

Below are those pieces of code combined in an iLogic rule, as well as a list box to choose the color scheme.

 

When I run this on an assembly and choose Forest I see the results shown in this image, I can choose a different scheme and see it change all of the thumbnails to that color scheme. I do not see any of them remaining as the dark gradient of Winter Night or any other anomalies.

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

 

image.png

 

Dim MyStringValues = New String(){"Presentation", "Winter Night", "Forest", "Sky"}

oScheme = InputListBox("select", MyStringValues, "Presentation", "iLogic", "List")

'Change to color scheme 
ThisApplication.ColorSchemes.Item(oScheme).Activate


'set to use gradient color background type
ThisApplication.ColorSchemes.BackgroundType = _
BackgroundTypeEnum.kGradientBackgroundType 


Dim oAsmDoc As AssemblyDocument
oAsmDoc = ThisApplication.ActiveDocument
Dim oDoc As Document

For Each oDoc In oAsmDoc.AllReferencedDocuments
    ' open document
    ThisApplication.Documents.Open (oDoc.FullFileName, True)
    
    For Each oSketch In oDoc.ComponentDefinition.Sketches
        oSketch.Visible = False
    Next
    
    'set work plane visibility
    For Each oWorkPlane In oDoc.ComponentDefinition.WorkPlanes
    oWorkPlane.Visible = False
    Next
    
    'set work axis visibility
    For Each oWorkAxis In oDoc.ComponentDefinition.WorkAxes
    oWorkAxis.Visible = False
    Next
    
    'set work point visibility
    For Each oWorkPoint In oDoc.ComponentDefinition.WorkPoints
    oWorkPoint.Visible = False
    Next

    'set iproperty to use ISO view on save
    oDoc.SetThumbnailSaveOption _
    (ThumbnailSaveOptionEnum.kActiveComponentIsoViewOnSave)
    
    'save and close the file
    oDoc.Save
    oDoc.Close
Next

 

EESignature

0 Likes
Message 13 of 16

rcolon9E4ZX
Advocate
Advocate

Hi @Curtis_Waguespack ,

 

This is not a question about my code. This is about what Inventor is doing internally when it saves a thumbnail on document save. Without running any VBA code, these anomalies occur during normal design use with Inventor. This is strictly something Inventor is doing on its own and I want to find out why. I know I can refresh the thumbnails with a specific background from an earlier reply. I am not asking for code samples to loop through and refresh. I just want the understanding of what is causing this anomaly during normal Inventor use.

 

Thanks.

Rafael

0 Likes
Message 14 of 16

Curtis_Waguespack
Consultant
Consultant

 


Hi @rcolon9E4ZX ,

 

As far as I know the thumbnail will only get updated when that file is saved, so again if it is not getting updated I would guess that it is not getting saved.

 

The examples I've provided were intended so that you could run them and see if you can get the anomalies to go away.

 

I can not reproduce the anomalies you mention with code or without.

 

But indeed I was under the impression you were looking to fix an issue with your VBA macro that leaves some thumbnails not updated.

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

 

 

EESignature

0 Likes
Message 15 of 16

rcolon9E4ZX
Advocate
Advocate

Hi @Curtis_Waguespack ,

 

Thanks. Rest assured, I do not get any anomalies when running VBA code to refresh the thumbnails. This is just a head scratcher as to why Inventor changes the background type sometimes for saved thumbnails. I will find out why, and update this thread when I do.

 

Rafael

0 Likes
Message 16 of 16

Curtis_Waguespack
Consultant
Consultant

Hi @rcolon9E4ZX 

 

I guess the only time I've seen the thumbnail colors change "magically" is when someone else saves the file on another machine/profile that is using a different color scheme. I guess I didn't think of this as an anomaly, but I guess it could seem that way if we're not aware that is going on?  So maybe the idea that someone else is saving the files using a different color scheme is something to rule out? 

 

Which brings me to another thought, which might be that if you have Task Scheduler running a migration task during upgrades... it uses a "headless" Inventor that uses default settings ... this might update thumbnails as it saves? I'm not sure if that is true or not, but something that came to mind, so again maybe something to rule out?

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

EESignature

0 Likes