13 Replies Latest reply on Apr 12, 2018 7:46 AM by Franz Dahinden

    Safe PDF and second PDF in specific Folder

    Franz Dahinden

      I have this macro and save the PDF in the same folder.

      I want to change the macro and save a second PDF in a specific folder. ----> In the end I have two PDF, but diferent places.

      Thanks a lot

       

      Does somebody has any idea?? is it ipossible?

        • Re: Safe PDF and second PDF in specific Folder
          Michael Spens

          Hello Franz,

          Yes, add another constant for a second folder location in your macro like this...

           

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

          Const Path2 As String = "C:\Drawing2" 'second path

           

          Then, add another SaveAs call that uses the second path like this...

           

           

          Part.SaveAs2 Path & "\" & saveFileName, 0, True, False

          Part.SaveAs2 Path2 & "\" & saveFileName, 0, True, False

           

          Mike

            • Re: Safe PDF and second PDF in specific Folder
              Franz Dahinden

              Hello Mike,

               

              it works fine, thank you very much.

              How I am change it, if one Path is at the same place as the drawing?

               

              Thank you very much in advance

                • Re: Safe PDF and second PDF in specific Folder
                  Deepak Gupta

                  For first path use (if you want to use just the path and not file name)

                   

                  Left(swModel.GetPathName, InStrRev(swModel.GetPathName, "\"))

                   

                  And if file name also then use (without . and extension)

                   

                  Left(swModel.GetPathName, InStrRev(swModel.GetPathName, ".") - 1)

                    • Re: Safe PDF and second PDF in specific Folder
                      Franz Dahinden

                      Hello Deepak,

                       

                      Thank you for your prompt reply. I am confused, which parts I should replace

                      Thanks a lot!!

                       

                      Dim swApp As Object
                      Dim Part As Object
                      Dim Artikelnr As String
                      Const CIIndex = "Index" 'Dateieigenschaft
                      Dim boolstatus As Boolean
                      Dim longstatus As Long, longwarnings As Long
                      Dim FeatureData As Object
                      Dim Feature As Object
                      Dim Component As Object
                      Dim AE As String
                      Dim saveFileName As String
                      Const Path As String = "C:\temp1" 'Change path here
                      Const Path2 As String = "C:\temp1\temp2" 'Change path here

                       

                       

                      Sub main()

                      Set swApp = Application.SldWorks

                      Set Part = swApp.ActiveDoc
                      swApp.ActiveDoc.ActiveView.FrameState = 1
                      swApp.ActiveDoc.ActiveView.FrameState = 1
                      Part.EditSketch

                      If (swApp.ActiveDoc.GetPathName = "") Then          'Abfrage ob Name vergeben wurde
                          MsgBox ("Bitte zuerst Zeichnung speichern!")
                          Exit Sub


                      End If

                      Index = Part.CustomInfo2("", CIIndex)

                         If Index = "0" Then
                          AE = ""
                          Else
                          AE = "_V" & Index


                          End If

                      saveFileName = Mid(swApp.ActiveDoc.GetPathName, InStrRev(swApp.ActiveDoc.GetPathName, "\") + 1)
                      saveFileName = Left(saveFileName, InStrRev(saveFileName, ".") - 1) + AE + ".pdf"   ' Speichern als PDF-Datei

                      Part.SaveAs2 Path & "\" & saveFileName, 0, True, False
                      Part.SaveAs2 Path2 & "\" & saveFileName, 0, True, False

                       

                      End Sub

                        • Re: Safe PDF and second PDF in specific Folder
                          Deepak Gupta

                          Franz Dahinden wrote:

                           

                          Hello Deepak,

                           

                          Thank you for your prompt reply. I am confused, which parts I should replace

                          Replace

                           

                          this line

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

                          to

                           

                          Dim Path As String

                           

                           

                          And this line

                          Part.SaveAs2 Path & "\" & saveFileName, 0, True, False

                          to

                          Part.SaveAs2 Left(swModel.GetPathName, InStrRev(swModel.GetPathName, "\")) & saveFileName, 0, True, False

                            • Re: Safe PDF and second PDF in specific Folder
                              Franz Dahinden

                              Hello Deepak,

                               

                              I get this ERROR?

                               

                               

                                • Re: Safe PDF and second PDF in specific Folder
                                  Deepak Gupta

                                  Oops, sorry. Replace swModel with Part in that line.

                                    • Re: Safe PDF and second PDF in specific Folder
                                      Franz Dahinden

                                      I still get this

                                       

                                      Dim swApp As Object
                                      Dim Part As Object
                                      Dim Artikelnr As String
                                      Const CIIndex = "Index" 'Dateieigenschaft
                                      Dim boolstatus As Boolean
                                      Dim longstatus As Long, longwarnings As Long
                                      Dim FeatureData As Object
                                      Dim Feature As Object
                                      Dim Component As Object
                                      Dim AE As String
                                      Dim saveFileName As String
                                      Dim Path As String
                                      Dim swModel As SldWorks.ModelDoc2
                                      Const Path2 As String = "C:\temp1" 'Change path here

                                       

                                       

                                      Sub main()

                                      Set swApp = Application.SldWorks

                                      Set Part = swApp.ActiveDoc
                                      swApp.ActiveDoc.ActiveView.FrameState = 1
                                      swApp.ActiveDoc.ActiveView.FrameState = 1
                                      Part.EditSketch

                                      If (swApp.ActiveDoc.GetPathName = "") Then          'Abfrage ob Name vergeben wurde
                                          MsgBox ("Bitte zuerst Zeichnung speichern!")
                                          Exit Sub
                                      End If

                                       

                                      Index = Part.CustomInfo2("", CIIndex)

                                         If Index = "0" Then
                                          AE = ""
                                          Else
                                          AE = "_V" & Index
                                          End If

                                       

                                      saveFileName = Mid(swApp.ActiveDoc.GetPathName, InStrRev(swApp.ActiveDoc.GetPathName, "\") + 1)
                                      saveFileName = Left(saveFileName, InStrRev(saveFileName, ".") - 1) + AE + ".pdf"   ' Speichern als PDF-Datei

                                       

                                      Part.SaveAs2 Left(swPart.GetPathName, InStrRev(swPart.GetPathName, "\")) & saveFileName, 0, True, False
                                      Part.SaveAs2 Path2 & "\" & saveFileName, 0, True, False

                                       

                                      End Sub

                                      • Re: Safe PDF and second PDF in specific Folder
                                        Franz Dahinden

                                        Hello Deepak Gupta,

                                        thank you very much, works fine

                                      • Re: Safe PDF and second PDF in specific Folder
                                        Mario Zahren

                                        Hi,

                                        ich glaube das hier hast Du vergessen:

                                         

                                        "Dim swModel As SldWorks.ModelDoc2" <--

                                         

                                        Set swApp = Application.SldWorks

                                        "Set swModel = swApp.ActiveDoc" <--

                                         

                                        Gruß

                                        Mario

                                          • Re: Safe PDF and second PDF in specific Folder
                                            Franz Dahinden

                                            Hallo Mario

                                             

                                            Set swModel = swApp.ActiveDoc

                                             

                                            geht auch nicht

                                             

                                            Gruss Franz

                                              • Re: Safe PDF and second PDF in specific Folder
                                                Mario Zahren

                                                Sorry ich habe den Code nicht ganz gelesen.

                                                Deepak hat aber recht. Hier der Code:

                                                 

                                                Dim swApp As Object
                                                Dim Part As Object
                                                Dim Artikelnr As String
                                                Const CIIndex = "Index" 'Dateieigenschaft
                                                Dim boolstatus As Boolean
                                                Dim longstatus As Long, longwarnings As Long
                                                Dim FeatureData As Object
                                                Dim Feature As Object
                                                Dim Component As Object
                                                Dim AE As String
                                                Dim saveFileName As String
                                                Dim Path As String '<-- Hier die Variable definieren
                                                Dim swModel As SldWorks.ModelDoc2
                                                
                                                'Das brauchst du nicht (siehe var Path).
                                                'Const Path As String = "C:\temp1" 'Change path here
                                                'Const Path2 As String = "C:\temp1\temp2" 'Change path here
                                                
                                                Sub main()
                                                
                                                Set swApp = Application.SldWorks
                                                Set Part = swApp.ActiveDoc
                                                swApp.ActiveDoc.ActiveView.FrameState = 1
                                                swApp.ActiveDoc.ActiveView.FrameState = 1
                                                Part.EditSketch
                                                
                                                Path = "C:\temp1" '<-- Hier den Wert zuweisen
                                                
                                                If (swApp.ActiveDoc.GetPathName = "") Then          'Abfrage ob Name vergeben wurde
                                                    MsgBox ("Bitte zuerst Zeichnung speichern!")
                                                    Exit Sub
                                                
                                                
                                                End If
                                                
                                                Index = Part.CustomInfo2("", CIIndex)
                                                
                                                   If Index = "0" Then
                                                    AE = ""
                                                    Else
                                                    AE = "_V" & Index
                                                
                                                
                                                    End If
                                                
                                                saveFileName = Mid(swApp.ActiveDoc.GetPathName, InStrRev(swApp.ActiveDoc.GetPathName, "\") + 1)
                                                saveFileName = Left(saveFileName, InStrRev(saveFileName, ".") - 1) + AE + ".pdf"   ' Speichern als PDF-Datei
                                                
                                                'Part.SaveAs2 Path & "\" & saveFileName, 0, True, False
                                                Part.SaveAs2 Left(Part.GetPathName, InStrRev(Part.GetPathName, "\")) & saveFileName, 0, True, False
                                                Part.SaveAs2 Path & "\" & saveFileName, 0, True, False
                                                
                                                End Sub