8 Replies Latest reply on Nov 24, 2014 3:40 AM by Angel Serrano

    CONVERT TO JPG

    Angel Serrano

      Hello Everyone,

       

      I am using Edrawings and the eDrawings API, so the needed help is for the eDrawings API.

       

      Could you please help me, i am new using VBA, to create a macro to convert the solidworks document to a JPG file?

       

      I need to do it in MS Access or Excell, and i need it for the active (open) file on the screen.

       

      I really appreciate any help.

       

      Thank you in advance.

        • Re: CONVERT TO JPG
          Daniel Andersson

          Could you explain a bit more about  the  process. What applications is running and from where is the macro thought to be executed? What should happen in the excel file?

            • Re: CONVERT TO JPG
              Angel Serrano

              Thanks a lot Daniel for your fast answer.

               

              The proccess is as follows:

              - The user introduce the name of the Solidworks file (SLDPRT, SLDASM, SLDDRW)  on an input field (textbox)  in an Access form.

              - The form has an activex control (edrawings API) to show on the screen the selected file.

              - Then there is a command button that is press by the user, and i link the button to VBA code.

              - That VBA code is where i want to do a "SAVE AS", so what i need is to save the active file as a .JPG file

              - The user will use that JPG file to put some notes and to do little changes.

               

              I have to say that the user don´t have Solidworks on his system, but just Edrawings

               

              I hope this help you to understand what i want, if not please don´t hesitate to ask me.

               

              Thank you very much.

                  • Re: CONVERT TO JPG
                    Angel Serrano

                    Thanks for your help Daniel.

                     

                    I am sorry but a have that found before. The problem is that it is programmed in Visual Basic (VB) and what i need is Visual Basic for Aplications (VBA), so i can not use that code with MS Access.

                     

                    Best regards,

                      • Re: CONVERT TO JPG
                        Daniel Andersson

                        The eDrawing API is use able in vba as well. You have to add it as refenced library in the vba editor for the macro you are creating.

                         

                        Have a look at Tools -> References in the vba editor in MS Access. There should be a eDrawing reference to select there.

                          • Re: CONVERT TO JPG
                            Angel Serrano

                            Thanks again Daniel.

                             

                            That is my problem, i found some references to do it, but i don´t understand the syntax of them, this is because i am new on VBA.

                             

                            Here is my code:

                             

                            Option Compare Database

                             

                            'To do the SAVE AS, when the user press a command button this part of the program runs

                            Private Sub PrintB_Click()

                                Dim file As String

                                file = "C:\asc\planosorig\" & Refer & ".SLDPRT"

                                Me.DWGImage.OpenDoc file, False, False, False, ""

                                file = "C:\asc\test.jpg"

                                EModelViewApp.SaveActiveDocumentAs (file) - THIS INSTRUCTION IS THE ONE FAILING, IT MUST BE SOMETHING STUPID, BUT I CAN´T SOLVE IT

                            End Sub

                             

                            'View the Solidwors file of the selected part number, done in an Edrwawings ActiveX of the Form

                                Private Sub Refer_AfterUpdate()

                                    Me.Refresh

                                    coutst = "C:\asc\planosorig\" & Refer & ".SLDPRT"

                                    DWGImage.Visible = True

                                    DWGImage.OpenDoc coutst, 0, 0, 0, ""

                                End Sub

                              • Re: CONVERT TO JPG
                                Daniel Andersson

                                Not sure if you solved it or not... but I do not regongnize the methods your are using for the DWGImage object. They are not found in the API where I look for the eDrawings 2014 API.

                                But it was quite straight forward since it is a inserted object. I tested this out in Excel 2013, should be similar in MS Access as well.

                                 

                                Inserted the eDrawings Active X by the Developer tab in Excel, click Insert, then More controls. Scroll down to eDrawings.

                                Add the object to the size you want...

                                Then I added two buttons... made this macro as below.

                                 

                                Cell B1 = C:\part1.sldprt

                                Cell B2 = C:\test1.jpg

                                 

                                Sub Button2_Click()

                                 

                                Sheet1.EModelViewControl1.CloseActiveDoc ""
                                Sheet1.EModelViewControl1.OpenDoc Sheet1.Cells(1, 2), False, False, True, ""

                                 

                                End Sub


                                Sub Button3_Click()

                                Sheet1.EModelViewControl1.Save Sheet1.Cells(2, 2), False, "" 'Save to the file as stated in cell B2

                                End Sub

                                 

                                 

                                I attached the excel file as well. The excel example was done with eDrawing 2014 x64.

                                 

                                EDIT 2014-12-04: Updated example so the open Solidworks document can be changed.

                                1 person found this helpful