Preview SolidWorks Files with an API

Hello

I have an application (VB6.0  32bit development, we can compare this to a VBA in Excel  32bit )

I have an "object" of type ImageList that I use to display the previews of the selected  files (I get the preview images from the Windows explorer)

it works fine with CATIA V5 / Autodesk  CAD files But my code doesn't work with SolidWorks files

(it's a 32-bit code that worked with a 32bit version of SolidWorks, but now with only a 64bit version :-( )

Is there a way to recover the preview image of a SolidWorks file, in a VBA (in 32bit)

--

I found "PreviewDoc" (see below),  but I didn't manage to use it (you have to compile a DLL, and I didn't understand how to get the image object .....)

=> have any of you ever done something similar? 

--

Then I thought of generating an image, but when I tested, I found the processing tesmps super long, not to mention the view to put in ISO and refocus .....

--

PreviewDoc code example

Dim instance As ISldWorks
Dim HWnd As System.Integer
Dim FullName As System.String
Dim value As System.Boolean
 
value = instance. PreviewDoc(HWnd, FullName)

Parameters

HWnd
Window handle where you want the preview bitmap to display; this pointer is not valid across processes; therefore, this method only works if your application is implemented as a DLL
FullName
Full path name of document to preview

 

Hello
I created an application in VB.Net that manages the relationship between our ERP and SolidWorks. In particular, she manages the injection of revisions into the ERP SQL database, the creation of PDF, DXF and eDrawings plans and the insertion of links in the database. It also creates JPG views of the parts and assemblies referenced in the ERP and then inserts the link into the database.

I had thought of getting the explorer preview but they are not all correct and even less in ISO orientation. On the other hand, the treatment is long. But we throw it about once a week.

Here's a simplified version of the feature that handles the generation of clips and images:

Sub TraitementCreaDocsSwPrt(ByVal Fichier As String, ByRef SW_Errors As Integer, ByRef SW_Warning As Integer, ByRef SW_Errors_MEP As Integer, ByRef SW_Warning_MEP As Integer)
        Dim SW_Model As SldWorks.ModelDoc2, SW_Model_MEP As SldWorks.ModelDoc2
        Dim SW_ModelDocExtension As SldWorks.ModelDocExtension
        Dim Info_MEP As FileInfo
        Try
            SW_Model = SW_App.OpenDoc6(Fichier, swDocumentTypes_e.swDocPART, swOpenDocOptions_e.swOpenDocOptions_Silent, "", SW_Errors, SW_Warning)
            If SW_Errors = Nothing Then
                SW_ModelDocExtension = SW_Model.Extension
                SW_ModelDocExtension.HideFeatureManager(True)
                SW_Model.ShowNamedView2("*Isométrique", swStandardViews_e.swIsometricView)
                SW_Model.ViewZoomtofit2()
                SW_Model.SaveAs3(Info_dossier_Export.FullName & "\" & Path.GetFileNameWithoutExtension(Fichier) & ".jpg", swSaveAsVersion_e.swSaveAsCurrentVersion, swSaveAsOptions_e.swSaveAsOptions_Silent)
                SW_Model.SaveAs3(Info_dossier_Export.FullName & "\" & Path.GetFileNameWithoutExtension(Fichier) & ".eprt", swSaveAsVersion_e.swSaveAsCurrentVersion, swSaveAsOptions_e.swSaveAsOptions_Silent)
                Info_MEP = New FileInfo(Left(Fichier, Fichier.Length - 7) & ".slddrw")
                If Info_MEP.Exists = True Then
                    SW_Model_MEP = SW_App.OpenDoc6(Info_MEP.FullName, swDocumentTypes_e.swDocDRAWING, swOpenDocOptions_e.swOpenDocOptions_Silent, "", SW_Errors_MEP, SW_Warning_MEP)
                    SW_Model.SaveAs3(Info_dossier_Export.FullName & "\" & Path.GetFileNameWithoutExtension(Fichier) & ".dxf", swSaveAsVersion_e.swSaveAsCurrentVersion, swSaveAsOptions_e.swSaveAsOptions_Silent)
                    Export_Pdf(SW_App, SW_Model_MEP, Info_dossier_Export.FullName & "\" & Path.GetFileNameWithoutExtension(Fichier) & ".pdf")
                Else
                    ' Traitement de l'erreur de présence de la MEP
                End If
            Else
              ' Traitement de l'erreur d'ouverture du fichier
            End If
            If ProcessSW.HasExited = False Then
                SW_App.CloseAllDocuments(True)
            End If
        Catch Ex As Exception
            ' Traitement de l'erreur
        End Try
End Sub

 

My application is in 64bits. I don't think it's possible to code a 32bit.

I hope I helped you.
Have a nice day