'Is there a way in VBA solidworks to force the recreation of thumbnail?
I have 5000 converted cad files from an old system. Usually SolidWorks creates thumbnails that can bee seen in Windows Explorer as a preview. Unfortunately, the thumbnails are showing the part in miniature. This is caused by the conversion - the part is positioned outside the active screen area, and the thumbnail is created from that, thus showing a ridicules large area in the thumbnail.

The manual resolution:
- open the part in SolidWorks
- Scale to fit to get the part in the viewing area at max size
- rebuild the part
- save the part (after saving, the correct thumbnail is directly visible in Explorer)
- close the SolidWorks window
This works, I now created a VBA code to do the same, it does all the above except the recreation of the thumbnail.
Sub main()
Dim swApp As Object
Dim swModelDoc As SldWorks.ModelDoc2
Dim Part As Object
Dim boolstatus As Boolean
Dim longstatus As Long, longwarnings As Long
Dim FileName As String
Dim Path As String
Set swApp = Application.SldWorks
Set Part = swApp.ActiveDoc
Set swModelDoc = swApp.ActiveDoc
With swModelDoc
Path = .GetPathName
FileName = .GetTitle
.ViewZoomtofit2
.ForceRebuild3 True
.GraphicsRedraw2
.Save
End With
Set swApp = Application.SldWorks
Set swPart = Nothing
Set Part = Nothing
swApp.CloseDoc FileName
End Sub
As far as I can see this is done during the save operation, I cant see what I am missing.
Does anyone know how to force the creation of the thumbnail during or before the save action?
Solution 1:[1]
Below is a part of a Macro i made while back, that ends by making a zoom-to-fit, and saves the file to a new location; i know this is generating the correct thumbnails... the only real difference i see, is that i use SaveAs, could you give that a try, and simply letting it overwrite the old file?
'Zoom to Fit
swModel.ViewZoomtofit2
'declare a new location for the file, and save it, using the original file-name.
Dim saveFile As Long
saveFile = swModel.SaveAs3(path & "Output\" & sFileName, 0, 0)
'Get title of the open file, and close it.
Dim partTitle As String
partTitle = swModel.GetTitle
swApp.CloseDoc partTitle
If you are still having problems; where are your files located? if they are being handled in a PDM-Vault, it could very well be the environments that holds on to the old thumbnails.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | HJbuhrkall |
