3 Replies Latest reply on Nov 25, 2015 1:59 AM by Franz Dahinden

    Singles PDF (current) with sheet name and Index macro

    Franz Dahinden

      I would like to change the macro. The name of the current sheet and the index from part or assy  (inkl. already) should be stored in file of PDF. 

      For example-->  Massbild-FileNr.-sheetname-A. --> Massbild-455266-coverplate-A.
      It should save only the current sheet.
      Anyone can help me for add the necessary Information.

        • Re: Singles PDF (current) with sheet name and Index macro
          Dmitry Zamoshnikov

          look up:




          You'll have to parse the file name.


          filepath = ModelDoc2.GetPathName


          /* search for the final occurance of the '/' character in the file path.

             that will get you the index

             do newFilepath = Strings.Right(filepath, Strings.Len(filepath)-index)) to parse out the file name

             newFilepath = Strings.Left(newFilePath, Strings.Len(newFilePath)-7 to get rid of the extension

             Now you can start to add things to the file path


            • Re: Singles PDF (current) with sheet name and Index macro
              Franz Dahinden

              Hello Dmitry Zamoshnikov,


              thanks für help.  I should change my macro PDF-Revision or the macro from SolidWorks?

              Perhaps is to difficult for me, if you not tell me wich line i have to change.



              ' Preconditions: The specified drawing document exists.


              '                NOTE: The  drawing document is installed when

              '                      you  install SolidWorks.


              ' Postconditions: The specified sheet is exported to a  PDF file.


              Option Explicit


                  Dim  swApp               As  SldWorks.SldWorks

                  Dim  swModel             As  SldWorks.ModelDoc2

                  Dim  swModelDocExt       As  SldWorks.ModelDocExtension

                  Dim  swExportPDFData     As  SldWorks.ExportPdfData

                  Dim  boolstatus          As  Boolean

                  Dim  filename            As  String

                  Dim  lErrors             As  Long

                  Dim  lWarnings           As  Long

                  Dim  strSheetName(4)     As  String

                  Dim  varSheetName        As  Variant


              Sub main()


                  '  Path to which to save PDF file of drawing

                  filename  = "C:\foodprocessor.PDF"


                  Set  swApp = Application.SldWorks

                  swApp.Visible  = True


                  '  Open specified drawing

                  Set  swModel = swApp.OpenDoc6("c:\Program  Files\SolidWorks\samples\tutorial\advdrawings\foodprocessor.slddrw",  swDocDRAWING, swOpenDocOptions_Silent, "", lErrors, lWarnings)

                  Set  swModelDocExt = swModel.Extension


                  Set  swExportPDFData = swApp.GetExportFileData(1)


                  '  Names of the sheets

                  strSheetName(0)  = "Sheet1"

                  '  strSheetName(1) = "Sheet2"

                  '  strSheetName(2) = "Sheet3"

                  '  strSheetName(3) = "Sheet4"


                  varSheetName  = strSheetName


                  If  swExportPDFData Is Nothing Then MsgBox "Nothing"

                  boolstatus  = swExportPDFData.SetSheets(swExportData_ExportSpecifiedSheets,  varSheetName)


              boolstatus = swModelDocExt.SaveAs(filename,  0, 0, swExportPDFData, lErrors, lWarnings)


              End Sub