5 Replies Latest reply on Mar 22, 2013 1:46 AM by Deepak Gupta

    PDF file name

    Wayne Schafer

      How do I code it to save the PDF as the current file name?

       

       

       

       

       

       

      pic1.png

        • Re: PDF file name
          Deepak Gupta

          Following codes will save the current active file as PDF in same location. In case you need to work it for only drawing, check the attached macro.

           

          Dim swApp As SldWorks.SldWorks

          Dim swModel As SldWorks.ModelDoc2

          Dim Path As String

          Sub main()

           

          Set swApp = Application.SldWorks

          Set swModel = swApp.ActiveDoc

           

           

          Path = Left(swModel.GetPathName, Len(swModel.GetPathName) - 6) & "PDF"

           

          swModel.SaveAs3 "" & Path & "", 0, 0

           

           

          End Sub

            • Re: PDF file name
              Wayne Schafer

              Thanks Deepak, but I do not want to save the PDF to the same file location as the slddrw location.  I need to choose a diffrent location on my local drive.  My solidworks drawing files that I would be saving as pdf's is on a network drive.

                • Re: PDF file name
                  Jeremiah Davis

                  This is the code I like to use:

                   

                  Dim swModExt As SldWorks.ModelDocExtension

                  Dim SwModel As SldWorks.ModelDoc2

                  Dim OutputPath As String

                  Dim SubDir As String

                  Dim RetBool As Boolean

                   

                  Set swModExt = SwModel.Extension

                   

                  If Dir(OutputPath & SubDir & SwModel.GetTitle & ".pdf") <> "" Then

                  Kill OutputPath & SubDir & swModel.GetTitle & ".pdf"

                  End If

                   

                   

                  RetBool = swModExt.SaveAs(OutputPath & SubDir & SwModel2.GetTitle & ".pdf", 0, 0, Nothing, Errors, Warnings)

                  Where OutputPath is the folder and SubDir is any sub-directories within that path.

                  • Re: PDF file name
                    Deepak Gupta

                    Will that path be fixed than you can hard code that into the macro else use browse option in macro.

                     

                    SaveAsPDF with Folder Selection

                • Re: PDF file name
                  Paul Marsman

                  you can use GetTitle() to get the name of the current file.  Depending on your Windows Explorer settings you will get the extension returned also.