8 Replies Latest reply on Jun 20, 2017 11:41 AM by Bobby Penland

    Save pdf in a specific folder

    Riccardo Rebichini

      Hi ,

      I am not expert in macro and I find on internet a macro to save in .pdf with a specific name built in this way: my code + revision + descriprion.

      Now I want to save my pdf in a specific folder. I found several macro on internet but I could not find the right way to use them.

      Anyone can help me to modify the following macro to reach the target?

      Thank you in advance!

       

      Option Explicit

       

      Dim swApp               As Object

      Dim Part                   As Object

      Dim FilePath             As String

      Dim PathSize            As Long

      Dim PathNoExtention     As String

      Dim NewFilePath         As String

      Dim Descrizione         As String

      Dim Revisione           As String

      Dim Codice              As String

      Dim Rev                 As String

       

      Sub main()

      Set swApp = Application.SldWorks

      Set Part = swApp.ActiveDoc

       

      FilePath = Part.GetPathName

      PathSize = Strings.Len(FilePath)

      Descrizione = Part.CustomInfo("Descrizione")

      Codice = Part.CustomInfo("Codice")

      Rev = Part.CustomInfo("Revisione")

       

      PathNoExtention = Strings.Left(FilePath, PathSize - 7)

       

      NewFilePath = Codice & "-Rev_" & Rev & "-" & Descrizione

       

      Part.SaveAs2 NewFilePath & ".PDF", 0, True, False

       

      End Sub

        • Re: Save pdf in a specific folder
          Deepak Gupta

          Riccardo, try these codes. I've added codes to check a drawing file is open. If you do not want to run it on drawing, remove the lines where it checks for the active file to be a drawing.

           

          Option Explicit
          Dim swApp           As SldWorks.SldWorks
          Dim swModel         As SldWorks.ModelDoc2
          Dim swDraw          As SldWorks.DrawingDoc
          Dim FileName        As String
          Dim Descrizione     As String
          Dim Codice          As String
          Dim Rev             As String
          Const Filepath      As String = "C:\Test PDF" 'Change Path here
          
          Sub main()
          Set swApp = Application.SldWorks
          Set swModel = swApp.ActiveDoc
          
          ' Check to see if a drawing is loaded.
          If swModel Is Nothing Then
          MsgBox "To be used for drawings only, Open a drawing first and then TRY!"
          Exit Sub
          End If
          
          If swModel.GetType <> swDocDRAWING Then
          MsgBox "To be used for drawings only, Open a drawing first and then TRY!"
          Exit Sub
          End If
          
          Set swDraw = swModel
          Descrizione = swDraw.CustomInfo("Descrizione")
          Codice = swDraw.CustomInfo("Codice")
          Rev = swDraw.CustomInfo("Revisione")
          
          FileName = Codice & "-Rev_" & Rev & "-" & Descrizione
          swDraw.SaveAs (Filepath + "\" + FileName + ".PDF")
          
          End Sub
          
            • Re: Save pdf in a specific folder
              Riccardo Rebichini

              Dear Deepak,

              thank you a lot. Your help is very precious.

              I have a similar macro for .x_t files that I use to save parts and assemblies.

              I tried to modify the macro for .pdf as following. It seems to work. Do you think it is ok?

               

              Option Explicit

              Dim swApp           As SldWorks.SldWorks

              Dim swModel         As SldWorks.ModelDoc2

              Dim swDraw          As SldWorks.ModelDoc

              Dim FileName        As String

              Dim Descrizione     As String

              Dim Codice          As String

              Dim Rev             As String

              Const Filepath      As String = "C:\" 'Change Path here

               

              Sub main()

              Set swApp = Application.SldWorks

              Set swModel = swApp.ActiveDoc

               

              ' Check to see if a model is loaded.

              If swModel Is Nothing Then

              MsgBox "To be used for parts or assemblies only. Open a part or an assembly first and then TRY!"

              Exit Sub

              End If

               

              If swModel.GetType = swDocDRAWING Then

              MsgBox "To be used for parts or assemblies only. Open a part or an assembly first and then TRY!"

              Exit Sub

              End If

               

              Set swDraw = swModel

              Descrizione = swDraw.CustomInfo("Descrizione")

              Codice = swDraw.CustomInfo("Codice")

              Rev = swDraw.CustomInfo("Revisione")

               

              FileName = Codice & "-Rev_" & Rev & "-" & Descrizione

              swDraw.SaveAs (Filepath + "\" + FileName + ".X_T")

               

              End Sub

            • Re: Save pdf in a specific folder
              Bobby Penland

              If you are using PDM Pro to store and release you CAD files you can use a 'Convert' task in your workflow to automatically create a pdf file in a specific folder once the workflow reaches an assigned state.