5 Replies Latest reply on Mar 30, 2015 4:14 AM by Deepak Gupta

    Macro to save PDF to another file folder ??

    Christopher Jones

      I have a macro that saves drawing with revision as PDF to current file location... Can i add to this macro that saves to another file location? Eg: c:\scans\2015\2015001-1 (-1 is the revision of macro) Also, to create folder 2015 if does not exist?

        • Re: Macro to save PDF to another file folder ??
          Deepak Gupta

          Yes it can be done. Can you add/upload the macro you're using so that macro can be updated to your needs?

           

          Check codes from this post to modify the macro yourself: Save Each Sheet As PDF - Help

            • Re: Macro to save PDF to another file folder ??
              Christopher Jones

              'File Save As PDF (referecned component custom property).swp -------------10/17/12

              'Description: Macro to save active drawing as PDF.
              'Precondition: Any active drawing with a view of component haveing the specified custom property.
              'Postcondition: Active drawing will be saved as PDF along with custom property value

              ' Please back up your data before use and USE AT OWN RISK

              ' This macro is provided as is.  No claims, support, refund, safety net, or
              ' warranties are expressed or implied.  By using this macro and/or its code in
              ' any way whatsoever, the user and any entities which the user represents,
              ' agree to hold the authors free of any and all liability.  Free distribution
              ' and use of this code in other free works is welcome.  If any portion of
              ' this code is used in other works, credit to the authors must be placed in
              ' that work within a user viewable location (e.g., macro header).  All other
              ' forms of distribution (i.e., not free, fee for delivery, etc) are prohibited
              ' without the expressed written consent by the authors.  Use at your own risk!
              ' ------------------------------------------------------------------------------
              ' Written by: Deepak Gupta (http://gupta9665.wordpress.com/)
              ' -------------------------------------------------------------------------------

              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

              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 Sheet = swApp.ActiveDoc.GetCurrentSheet

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

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

              Filepath = Left(swDraw.GetPathName, InStrRev(swDraw.GetPathName, "\"))

              FileName = Left(swDraw.GetTitle, Len(swDraw.GetTitle) - 9)

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

                • Re: Macro to save PDF to another file folder ??
                  Deepak Gupta

                  Try this one:

                   

                  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:\scans\2015" ' 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

                   

                  End Sub

                    • Re: Macro to save PDF to another file folder ??
                      Derek Soon

                      Hi Deepak,

                      I'm trying to modify from your script to add my company's revision number into the script and got into some problem, it totally never appear.

                      Can you please help to take a look?

                      Thank you very much in advance.

                       

                       

                       

                      Below is the copy of the script.

                       

                          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

                          Dim revision        As String

                         

                         

                       

                          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

                          

                          revision = swModel.GetCustomInfoValue("", "Rev")

                       

                          Filepath = "D:\temp" ' Change File Path here

                          Filepath = Filepath + "\"

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

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

                       

                          

                       

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

                          swDraw.SaveAs (Filepath + FileName + "rev" + revision + ".DXF")

                          

                       

                          End Sub

                        • Re: Macro to save PDF to another file folder ??
                          Deepak Gupta

                          Are you trying to read/use the drawing Revision property? If yes then remove these lines:

                           

                          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

                          And change this line:

                          revision = swModel.GetCustomInfoValue("", "Rev")

                          to

                          revision = swDraw.GetCustomInfoValue("", "Rev")