Thumbnail

Hi everyone

Anna Wood suggested I come here to see if someone could help.

Point one:

I would like to get SW to update the Thumbnail ever time I hit thesave.

Point Two

I have a part number creation spread sheet in excel and I wouldlike to have a picture ref to the thumbnail for prt, ass and drw.

Anna suggested that it would take a API in excel or something toachieve it. I have very little knowledge of such things couldsomeone help?? ,,,,,,, please
SolidworksApi macros
Answers 26
SF
SF 2009-01-16 Best Answer
As for the first request; I could swear there was a simplecheck-box in the options somewhere to tell it to update the previewimage on save, but for the life of my I cannot find it?

As for the second request. Your best bet is to use the DocumentManager to extract the actual bitmap from the files and then placeit as the source of a picturebox in excel. You could have thisrunning every time the excel sheet opened or just on a synchronisebasis where to save the bitmap to file and reference them.Unfortunately this is not exactly a beginners level task so youwould probably struggle.
JB
JB 2009-01-16
Luke,
Do you have any experience with this functionality? I got curiousand wrote a macro using SldWorks::GetPreviewBitmap (macroattached). It does work (saves out a bitmap), but contrary to theAPI help the picture isnot the same as what you see in the SolidWorks "Open"dialog. It seems to be just a screenshot of the model window at thetime of the last save rather than the nice isometric picture in thedialog. I seem to recall something about the preview image beingimproved for 2006, 2007, or 2008. Maybe that has something to dowith it. I haven't tested the Document Manager function of the samename. Another thing I wanted to look at but am not really sure ifit will even work for me is SldWorks::PreviewDoc. I only have VBA,so I don't know if I'd be able to figure out what to use for thehWnd argument.
SF
SF 2009-01-16
Yes the PreviewDoc, GetPreviewBitmap, and DM GetPreviewBitmapall pull in the same data and it should be correct. It is morelikely that the Open dialog is either pulling in a configurationspecific preview, or a cached version so the two mismatch.
SF
SF 2009-01-16
Thanks ........ I think

Josh the macro works, at first I thought it was not working till Ifond the bitmaps in the same folder as the file.

Sorry, is everyone saying that one can not write a VBA in excel todo the same as this macro, which could then save to a selectedcell?
JB
JB 2009-01-16
Did you try out the macro I posted? I get the general previewand the previews for each configuration. It is definitely pullingin a screenshot of the last-saved view of the model or drawing. Thesize of the bitmap is even exactly the same size pixel-wise as themodel window. If I zoom/pan/rotate and then save the model/drawingand pull the bitmap again it reflects the new screenshot. I guessthere's no way to access the pretty isometric view that shows up inthe Open dialog and on the Ctrl-Tab thumbnail preview?

I've attached a version that uses the document manager. Add licensekey string and stir.
JB
JB 2009-01-16
Can you even put a picture into a cell? I can't see how toinsert any picture into a cell of a spreadsheet, via programming ormanually.
IK
IK 2009-01-16
ActiveSheet.Range("G10").Select
ActiveSheet.Pictures.Insert( "path\name.jpg" )

I have attached Josh's sw macro as excell macro.
You must make reference to "C:\Program Files\CommonFiles\SolidWorks Shared\SwDocumentMgr.dll"

and you need access key for document manager fromapisupport
JB
JB 2009-01-16
Note that this code just dumps the picture on top of theExcel sheet with its top-left corner in the selected cell. It doesnot put the picture in a cell.
IK
IK 2009-01-16

Josh Brady wrote:

Note that this code just dumps the picture on top of the Excel sheet with its top-left corner in the selected cell. It does not put the picture in a cell.

that is true
SF
SF 2009-01-16
I can design an aircraft but you seem to have me over a log.I am so grateful for you help .... really mean that.

What and where is document manager?

How do I ask for an access key?

Again thank you so much for your help, if you ever need somethingdesigned, I would love to help.

Thank you Josh. Thank you Ivan and thanks everyone else
JB
JB 2009-01-16
The document manager is a .dll that enables certainnon-geometry related processing of SolidWorks files outside ofSolidWorks. It's pretty much the API arm of SolidWorks Explorer. Ifyou have a macro that uses it, you have to go toTools->References in the VBA editor and find "SwDocumentMgr 200xType Library" in the list. Then you have to put the license keystring somewhere in the code.

All you need to do in order to get the license key is send an emailto apisupport@solidworks.com and ask for it. You have to promisenot to tell anyone what it is - all secret like. I don't know whythey do this. Seems stupid to me. SW'07 sp0 didn't require thelicense key, (I'm pretty sure this was touted as a feature!) butthey locked it back up a couple of sp's later.

Anyone at SW care to comment on why? What's the rationalethere?
SF
SF 2009-01-16
Here is what I am trying to do

IK
IK 2009-01-16
something like this?
It is only solidworks api, so you don't need any key to useit.
JC
JC 2009-07-27

Public Sub pv(ByVal filePath As String )

     Dim pic as  System.Drawing.Bitmap
     Dim pvf As wpfPreviewFlowControl.wpfThumbnailCreator
     pvf = New wpfPreviewFlowControl.wpfThumbnailCreator()
     Dim size As System.Drawing.Size
     size.Width = 200 ' SIZE OF PREVIEW
     size.Height = 200 ' SIZE OF PREVIEW
     pvf.DesiredSize = Size
     pic =  pvf.GetThumbNail(filePath)

     pic .Save(NewPath)
End Function

add reference C:\Program Files (x86)\SolidWorks\SolidWorks Explorer 2008\wpfPreviewFlowControl.dll

need SolidWorks Explorer 2008

if this is the wrong Lang. or need help add reference  let me now


What program are you using (SW Macro,Visual Studio,Other)

Also There is noway to insert a pic into an excel sheet

excel is not made for that

have you thought of using access or an other database

JB
JB 2009-07-28
FYI Jacob, I haven't seen Doug around here for months, so you're not likely to get a response from him.
JB
JB 2009-07-28
I thought I would go ahead and give your code a shot.  I'm using VBA.  I can't add a reference to the file you suggested.  When I try, I get the error message "Can't add a reference to the specified file."  This occurs whether trying to create a macro in SolidWorks or Excel.
JB
JB 2009-07-28

Jacob

I also tried your code in a VSTA VB.net macro.  Didn't work there either.  I was able to add the reference, but I got the error below:

JC
JC 2009-07-28

I using this and it dose work in SW 2008 sp4 or sp5

It look's like it is a permission problem

SF
SF 2009-07-29
If you are using Vista make sure you either disable UAC or run SolidWorks with Admin privileges.
JB
JB 2009-07-29
Using XP 32 bit, and I'm pretty sure I'm local admin level.  Admittedly I'm very new at VSTA .net stuff.
SF
SF 2009-07-30
What is the exact code you are running, can you paste/upload it and I will test it
JB
JB 2009-07-30
All the code is actually shown in the picture I uploaded.  I'll zip and post the entire VSTA macro folder in a little while though.
JB
JB 2009-07-30
Here is the entire VSTA macro...
SF
SF 2009-07-30

The project runs fine as is so it is a permissions issue for sure.

This begs the question though why use this messy way of getting an image? It doesn't even get a large image its actually smaller than using the built in SW functions to get an image, which gives it you at the last display resolution the model was open on... this way gets thumbnail size; for example set the size to 2000x2000 and see the giant pixels. Compare that with GetPreviewBitmap which is totally fine.

JB
JB 2009-07-30
Which picture does this function get?  GetPreviewBitmap gets (as you said) the size, orientation, etc. that the model was last saved in.  Somewhere SW is getting some different, nice, isometric view to use in the Alt-Tab popup.  If this function gets that isometric I can certainly see why you would want to get that image.  Many times the last-saved view of the model is upside down, zoomed way in/out, or off-center so as to make the GetPreviewBitmap picture nearly useless.
JC
JC 2009-07-30

The Code is using a DLL from SolidWorks Explorer 2008

And it is for a Thumbnail view like in when tab through opend Files

The size I should have put smaller