5 Replies Latest reply on Feb 29, 2016 10:42 AM by Maynard Viersen

    Create image preview of SolidWorks Part

    Christian Estep

      Hey Everyone,

      I was wondering if anyone here knows how to insert an image preview of a Solidworks Part into a Custom Dialog box window? I'm trying to do this strictly using VBA, is this possible? Thanks in advance, for any help you all can provide on this important project. I appreciate it.

        • Re: Create image preview of SolidWorks Part
          Deepak Gupta

          You can save out a picture of part in a known location with know name. And then display that on the userform.

           

          Does this helps?

            • Re: Create image preview of SolidWorks Part
              Christian Estep

              Hey Guys, okay I've got my form working (mostly) in terms of inserting a Solidworks part using VBA coding. But I still need some help on how to use the code below for showing an image preview of the sldprt in a dialog box window for my custom userform.

               

              This is what I found online in the SolidWorks Help Section Online:

               

              Get Preview Bitmap Example (VBA)

              This example shows how to get the preview bitmap in a SOLIDWORKS document.

               

               

              '----------------------------------------------------

              ' Preconditions:

              ' 1. Verify that the specified part document exists.

              ' 2. Open the Immediate window.

              '

              ' Postconditions: Examine the Immediate window.

              '----------------------------------------------------

              Option Explicit

              Dim swApp As SldWorks.SldWorks

              Sub main()

                  Set swApp = Application.SldWorks

                  Dim p As stdole.StdPicture  'See MSDN for details about the StdPicture object

                  Dim fileName As String

                 

                  fileName = "C:\Program Files\SOLIDWORKS Corp\SOLIDWORKS\samples\tutorial\api\centerlink.sldprt"

                  Set p = swApp.GetPreviewBitmap(fileName, "Default")

                  Debug.Print "Handle: " & p.Handle

                  Debug.Print "Height: " & p.Height

                  Debug.Print "Width: " & p.Width

                  Debug.Print "Type (1 = bitmap): " & p.Type

              End Sub

               

              But my question is how do I use this? I know this code is just the nuts and bolts. What kind of parameters am I supposed to use to get the Debug.Print section to work properly? This is what I have so far in terms of code:

               

              Private Sub Image1_Click()

                  Dim swApp As SldWorks.SldWorks

                  Set swApp = Application.SldWorks

                  Dim p As stdole.StdPicture  'See MSDN for details about the StdPicture object

                  Dim fileName As String

                 

                  fileName = TextBox1.Text

                  Set p = swApp.GetPreviewBitmap(fileName, "Default")

                  Debug.Print "Handle: " & p.Handle

                  Debug.Print "Height: " & p.Height

                  Debug.Print "Width: " & p.Width

                  Debug.Print "Type (1 = bitmap): " & p.Type

              End Sub

               

              I'm trying to get this specific code to create an image preview that will appear in the blank window in my dialog box shown below:

              CustomDialog1.png

              • Re: Create image preview of SolidWorks Part
                Christian Estep

                Hey guys,

                 

                Thanks for getting back with me so quickly on this problem. To Deepak's post, no I'm trying to get a loaded preview image of a file. Not trying to load in a previously saved image, but I appreciate the comment. Thank-you Mr. Gupta.

                 

                Hey Maynard, I was wondering if a similar example exists for VBA? Since I know that the coding is somewhat different between VB.NET and VBA. Sorry, I'm on my way to learning this coding stuff but still have alot of questions.