Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TugboatEng on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

THUMBNAIL VIEW to EXCEL

Status
Not open for further replies.

SWmunky

New member
Joined
Apr 30, 2007
Messages
5
Location
US
I am trying to see if it is possible to take the thumbnail view that you see when opening a file and placing it in another program as a picture. Has anyone tried this and if so how do you do it?

Thanks
 
That file is a Bitmap image saved in the file code itself. If you can extract that being a code writer then maybe otherwise you won't be able too. You can do a Screen capture (alt-Print screen) and it will capture the active window. Use a Image software (Example: Paint shop pro) and crop it to fit and place that in Excel.

Regards,

Scott Baugh, CSWP [pc2]
"If it's not broke, Don't fix it!"
faq731-376
 
There is some sample code in the SW API Help to extract the bitmap directly from the SolidWorks file. The code works great if in a SolidWorks Macro. But if I use that same code in an Excel Macro, I get a "Catastrophic Failure" Run-time Error. So the work around I've been doing is to save a jpeg of the SW file each time, then display that jpeg in Excel.

Here is the code to extract the preview image. You'll need a form called "Userform1", an image box called "Image1", and a file at "C:\Part1.SLDPRT".

If you get this to work let me know,
Ken

Code:
Option Explicit

Sub GetSwPreviewImage(strSwPreviewFilenameAndPath As String, Optional strSwConfig As String)
    
    Dim swApp As SldWorks.SldWorks
    Dim swPreview As IPictureDisp
'    Dim swPreview As stdole.StdPicture  'Get Preview Bitmap Example (VB), See MSDN for details about the StdPicture object
    Dim vConfName As Variant
    Dim lngCount As Long
    Dim boolConfigNameExists As Boolean
    
'Need this for SW    Set swApp = Application.SldWorks
'Need this for Excel    Set swApp = GetObject(, "SldWorks.Application")
    
    vConfName = swApp.GetConfigurationNames(strSwPreviewFilenameAndPath)
    If IsEmpty(vConfName) Then
        vConfName = swApp.GetConfigurationNames(strSwPreviewFilenameAndPath)
    End If
    
    boolConfigNameExists = False
    For lngCount = 0 To UBound(vConfName)
        If vConfName(lngCount) = strSwConfig Then
            boolConfigNameExists = True
        End If
    Next lngCount
    
    If boolConfigNameExists Then
        'nothing
    Else
        boolConfigNameExists = False
        For lngCount = 0 To UBound(vConfName)
            If vConfName(lngCount) = "Default" Then
                boolConfigNameExists = True
            End If
        Next lngCount
        
        If boolConfigNameExists Then
            strSwConfig = "Default"
        Else
            strSwConfig = vConfName(1)
        End If
    End If

    Set swPreview = swApp.GetPreviewBitmap(strSwPreviewFilenameAndPath, strSwConfig)
'    Set UserForm1.Image1.Picture = swPreview
    
End Sub

Sub main()

    Load UserForm1
    
    Call GetSwPreviewImage("C:\Part1.SLDPRT", "Default")
    
    UserForm1.Show

End Sub


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top