16 Replies Latest reply on Aug 21, 2017 8:47 AM by Daniel McBride

    Save as step/sldprt/dxf/pdf from drawing

    Ian McLean

      Hi, I need a macro that saves a drawing as dxf and pdf, and also the part as a step and sldprt all with the drawing revision on the end, and to a particular folder.

      We need the sldprt with revision to send to sheetmetal suppliers who do their brake press programming in Solidworks addin

      I was able to mod the macro here:

      How to make a macro that saves a part as STEP in a specific folder using property name i file name?

       

      and add bit to save as sldprt but:

       

      If the drawing is saved, it saves linked to the part with revision on the end rather than the original part.

      Is there an option to use the "file save as copy and continue"?

      When I record this as a macro it seems to put 0,3 on the end but the linked macro doesn't seem to have this bit for the save as step

       

      Also I need to add in the path to save the files to.

       

      Any help greatly appreciated:), as you can probably tell my API expertise is near zero.

        • Re: Save as step/sldprt/dxf/pdf from drawing
          Kevin Chisholm

          Hi Ian,

           

          For the SaveAs Copy, you can add these options for the SaveAs command :

           

          So if you change the swSaveAsOptions_Silent to swSaveAsOptions_Copy + swSaveAsOptions_Silent,

          it should do both. You can also only write 1 + 2 and it will do the same thing.

           

          Do you want the path to be "User" selected or predefined?

          • Re: Save as step/sldprt/dxf/pdf from drawing
            Deepak Gupta

            Here is updated macro to save the step/sldprt/dxf/pdf in the specified folder. Change the path as required and make sure to add \ at end of path (like I've added).

             

            Check/Use fixed macro from post below: https://forum.solidworks.com/message/566804#comment-566804

              • Re: Save as step/sldprt/dxf/pdf from drawing
                Ian McLean

                Hi Deepak,

                    thank you very much for your help:) .

                The macro doesn't seem to run at my end when I have drawing open.

                To try and check what's happening I ran with nothing open and with a part open and both of the Msgboxs show up.

                If I try and run with a drawing with no view the macro stops with Run time error 91 here:

                2016-03-10 09_03_47-Microsoft Visual Basic for Applications - Create_DXF_PDF_STEP [break] - [DXF_PDF.png

                This doesn't happen if there is a view, in that case nothing happens at all, (pretty sure I put the path in OK)

                We are running Solidworks 2015 on Win 7x64 if that matters.

                Thanks again for your help.

                • Re: Save as step/sldprt/dxf/pdf from drawing
                  Daniel McBride

                  Hey guys, I'm trying to do the same thing as Ian but can't get the save as copy command to take. Below is an except from the macro (Deepak's). What needs to change to get "save as copy and continue" to work? Any assistance is greatly appreciated. Also if there is a way to as saving (save as copy) the part/assy file at the same time that would be ideal!

                   

                  Option Explicit

                  Dim swApp           As SldWorks.SldWorks

                  Dim swModel         As SldWorks.ModelDoc2

                  Dim swDraw          As SldWorks.DrawingDoc

                  Dim swCustProp      As CustomPropertyManager

                  Dim valOut          As String

                  Dim resolvedValOut  As String

                  Dim Filepath        As String

                  Dim FileName        As String

                  Dim swView          As SldWorks.View

                   

                  Sub main()

                  Set swApp = Application.SldWorks

                  Set swDraw = swApp.ActiveDoc

                   

                  ' Check to see if a drawing is loaded.

                  If (swDraw Is Nothing) Or (swDraw.GetType <> swDocDRAWING) Then

                  swApp.SendMsgToUser ("To be used for drawings only, Open a drawing first and then TRY!")

                  ' If no model currently loaded, then exit

                  Exit Sub

                  End If

                   

                  Set swView = swDraw.GetFirstView

                  Set swView = swView.GetNextView

                  Set swModel = swView.ReferencedDocument

                   

                  Set swCustProp = swModel.Extension.CustomPropertyManager("")

                  swCustProp.Get2 "Revision", valOut, resolvedValOut 'Change the custom property name here

                   

                  Filepath = "C:\Users\dan\Desktop" ' Change File Path here

                  Filepath = Filepath + "\"

                   

                  If Dir(Filepath) = "" Then

                          MkDir Filepath

                  End If

                   

                  FileName = Mid(swDraw.GetPathName, InStrRev(swDraw.GetPathName, "\") + 1)

                  FileName = Left(FileName, InStrRev(FileName, ".") - 1)

                   

                  swDraw.SaveAs (Filepath + FileName + "-" + resolvedValOut + ".PDF") 'Change the custom property text here

                  swDraw.SaveAs (Filepath + FileName + "-" + resolvedValOut + ".SLDDRW")

                   

                  End Sub

                   

                  Thanks in advance,

                   

                  Dan

                    • Re: Save as step/sldprt/dxf/pdf from drawing
                      Deepak Gupta

                      Comment out or remove these lines

                      If Dir(Filepath) = "" Then

                      MkDir Filepath

                      End If

                       

                      Replace these lines

                      swDraw.SaveAs (Filepath + FileName + "-" + resolvedValOut + ".PDF") 'Change the custom property text here

                      swDraw.SaveAs (Filepath + FileName + "-" + resolvedValOut + ".SLDDRW")

                      with

                       

                      Dim nErrors         As Long
                      Dim nWarnings       As Long
                      
                      
                      swDraw.Extension.SaveAs Filepath + FileName + "-" + resolvedValOut + ".PDF", swSaveAsCurrentVersion, swSaveAsOptions_Silent, Nothing, nErrors, nWarnings   
                      swDraw.Extension.SaveAs Filepath + FileName + "-" + resolvedValOut + ".SLDDRW", swSaveAsCurrentVersion, swSaveAsOptions_Copy + swSaveAsOptions_Silent, Nothing, nErrors, nWarnings
                      swModel.Extension.SaveAs Filepath + FileName + "-" + resolvedValOut + ".sldprt", swSaveAsCurrentVersion, swSaveAsOptions_Copy + swSaveAsOptions_Silent, Nothing, nErrors, nWarnings