5 Replies Latest reply on Jan 18, 2018 7:08 AM by Deepak Gupta

    Edit macro to save as pdf with current drawing revision rather than model revision.

    Dorian Mardi

      Anyone able to edit the macro below to save as pdf with current sheet revision (from drawing file properties)?

      Current macro saves the drawing as pdf, but uses "revision" from custom properties in the 3d model.

       

       

       

      Option Explicit

          Dim swApp                   As SldWorks.SldWorks

          Dim swModel                 As SldWorks.ModelDoc2

          Dim sPathName               As String

          Dim sRev                    As String

          Dim nRetval                 As Long

          Dim bShowMap                As Boolean

          Dim swModelDocExt           As SldWorks.ModelDocExtension

          Dim swExportData            As SldWorks.ExportPdfData

          Dim boolstatus              As Boolean

          Dim swCustProp              As CustomPropertyManager

          Dim valOut                  As String

          Dim resolvedValOut          As String

          Dim swView                  As SldWorks.View

             

      Sub main()

          Set swApp = Application.SldWorks

          Set swModel = swApp.ActiveDoc

       

       

          sPathName = swModel.GetPathName

          sPathName = Left(sPathName, Len(sPathName) - 7)

         

          If (swModel.GetType = SwConst.swDocumentTypes_e.swDocDRAWING) Then

             

              Set swView = swModel.GetFirstView

              Set swView = swView.GetNextView

              Set swCustProp = swView.ReferencedDocument.Extension.CustomPropertyManager("")

              swCustProp.Get2 "Revision", valOut, resolvedValOut

                    

              bShowMap = swApp.GetUserPreferenceToggle(swDXFDontShowMap)

              Set swExportData = swApp.GetExportFileData(swExportPDFData)

              boolstatus = swExportData.SetSheets(swExportData_ExportAllSheets, 1)

              boolstatus = swModel.Extension.SaveAs(sPathName + "-" + resolvedValOut + ".PDF", 0, 0, swExportData, 0, 0)

              swApp.SetUserPreferenceToggle swDXFDontShowMap, False

              swApp.SetUserPreferenceToggle swDXFDontShowMap, bShowMap

              If boolstatus Then

                  MsgBox "Save as PDF successful, WOOT!" & vbNewLine & sPathName + "...PDF, DWG, DXF"

              Else

                  MsgBox "Save as PDF failed." '

              End If

          Else

              boolstatus = swModel.SaveAs4(sPathName + ".step", swSaveAsCurrentVersion, swSaveAsOptions_Silent, 0, 0)

          End If

      End Sub

       

       

      '----------------------------------------------