2 Replies Latest reply on Feb 25, 2014 6:36 AM by Artem Taturevych

    Save As PDF with Correct Filename

    Fraser Reekie



      I am modifying an existing macro to save a drawing as a pdf document in specific file location with the revision in the filename. The macro now does both of these things however the filename is not correct. The pdf should be named with the same name as the drawing, instead it is saved with the same name as the drawing plus the sheet name, e.g. SG828456DML - Sheet1_A00 instead of SG828456DML_A00 (SG828456DML is the name of the drawing and _A00 is the revision).


      Public Sub main()


              Dim swDoc As ModelDoc2 = Nothing

              Dim longstatus As Integer = 0

              swDoc = CType(swApp.ActiveDoc, ModelDoc2)

              Dim FilePath As String = ""

              Dim FileRevision As String = ""

              Dim NewFilePath1 As String = ""

              Dim NewFilePath2 As String = ""



              FilePath = swDoc.GetTitle

              FileRevision = swDoc.GetCustomInfoValue("", "Révision")

              NewFilePath2 = (FilePath & "_" & FileRevision)

              NewFilePath1 = Path.ChangeExtension("S:\Wide\Gattlen\FRE\In approval process\" & NewFilePath2, ".PDF")


              longstatus = swDoc.SaveAs3(NewFilePath1, 0, 0)

              MsgBox("Saved " & NewFilePath1, MsgBoxStyle.Information)


      End Sub







        • Re: Save As PDF with Correct Filename
          Deepak Gupta

          Try these codes


          Dim swApp As SldWorks.SldWorks

          Dim swModel As SldWorks.ModelDoc2

          Dim sFileName As String

          Dim FileRevision As String

          Const FilePath As String = "S:\Wide\Gattlen\FRE\In approval process\"

          Sub main()


          Set swApp = Application.SldWorks

          Set swModel = swApp.ActiveDoc


          FileRevision = swModel.GetCustomInfoValue("", "Révision")

          sFileName = Mid(swModel.GetPathName, InStrRev(swModel.GetPathName, "\") + 1)

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


          sFileName = FilePath & sFileName & "_" & FileRevision & ".PDF"


          swModel.SaveAs3 sFileName, 0, 0       

          MsgBox "Saved " sFileName, vbOKOnly


          End Sub

          • Re: Save As PDF with Correct Filename
            Artem Taturevych

            You are using VB.NET so you can just call


            FilePath = Path.GetFileNameWithoutExtension(swDoc.GetPathName())

            instead of


            FilePath = swDoc.GetTitle