11 Replies Latest reply on Apr 11, 2018 11:58 PM by Prasanna Ashok

    Macro Export PDF Custom File Name & Settings

    Arne Currie

      Hello,

      I have a macro (attached) that exports all the sheets in a drawing to separate sheets with names the same as each sheet.

       

      I want to make it so that the file name of the pdf's is 'drawing_name sheet_name.pdf' so if the drawing is 'CQ101 2 x 1 x 150.slddrw' and this has 2 sheets called 'Sheet1' and 'Quote' will create a pdf of each sheet named      'CQ101 2 x 1 x 150 Sheet1.pdf'      and      'CQ101 2 x 1 x 150 Quote.pdf'     respectively.

       

      On a side note, I also want to always export in color, embed fonts, use high quality lines and high quality shaded edges, if that's possible.

       

      Thanks for your help in advance!

       

      Cheers,

      Arne

        • Re: Macro Export PDF Custom File Name & Settings
          Viktor Bovzdarenko

          Hi Arne,

          I modified your macro to include the path of the drawing and the sheet name:

           

          Dim drawingName As String:  drawingName = Left(swModel.GetPathName(), InStrRev(swModel.GetPathName(), ".") - 1)

          swModel.Extension.SaveAs drawingName + " " + vSheetName + ".PDF", 0, 0, swExportPDFData, lErrors, lWarnings

           

          All other settings (color, embed fonts etc) need to be modified inside SolidWorks itself. Macro will just use default values.

           

           

          Alternatively try to use #TASK.  It allows to combine the name of the output file from different placeholders (including sheet name, configuration name, custom properties, date etc)

           

            • Re: Macro Export PDF Custom File Name & Settings
              Alex Burnett

              You can change settings within the VBA code with the following commands:

               

              ' Export PDF in Color
              swApp.SetUserPreferenceToggle swUserPreferenceToggle_e.swPDFExportInColor, false
              
              
              ' Embed Fonts
              swApp.SetUserPreferenceToggle swUserPreferenceToggle_e.swPDFExportEmbedFonts, true
              
              
              ' High Quality Lines Toggle and DPI
              swApp.SetUserPreferenceToggle swUserPreferenceToggle_e.swPDFExportHighQuality, false
              
              
              swApp.SetUserPreferenceIntegerValue swUserPreferenceIntegerValue_e.swPDFExportShadedDraftDPI, swDetailingStandard_e.swDetailingStandardISO
              
              
              swApp.SetUserPreferenceIntegerValue swUserPreferenceIntegerValue_e.swPDFExportOleDPI, swDetailingStandard_e.swDetailingStandardISO
              
              
              ' Print Header/Footer
              swApp.SetUserPreferenceToggle swUserPreferenceToggle_e.swPDFExportPrintHeaderFooter, false
              
              
              ' Use specified printer line weights
              swApp.SetUserPreferenceToggle swUserPreferenceToggle_e.swPDFExportUseCurrentPrintLineWeights, true
              
              
              ' Include layers set not to print
              swApp.SetUserPreferenceToggle swUserPreferenceToggle_e.swPDFExportIncludeLayersNotToPrint, false
              

               

              Edit: Fixed syntax for integer function

            • Re: Macro Export PDF Custom File Name & Settings
              Prasanna Ashok

              Hi All,

              Need solution?

               

              When i open "XXXX" drawing and save as pdf, default pdf name is "XXXX".pdf

               

              But our customer has requested for a new format going forward.

               

              Convention: Drawing Name_4digitsheetnumber_2digitrevision

               

              1. For single sheet "XXXX" dwg, Rev-0: XXXX_0001_00

               

              2. For 2 sheet "XXXX" dwg, Rev 1: XXXX_0001_01   (First sheet revision is 1)

                                                              : XXXX_0002_00  (Second sheet revision is 0)

               

              2. For 3 sheet "XXXX" dwg, Rev 1: XXXX_0001_01   (First sheet revision is 1)

                                                              : XXXX_0002_03  (Second sheet revision is 3)

                                                              : XXXX_0002_00  (Second sheet revision is 0)

               

              And so on... Above shown is just example.

               

              Is there macro to get this format while i do save as pdf? Revision number will be added into part "model properties".

               

              So drawing title block will have drawing number, revision and sheet number information.

               

              Using this how to get the required pdf naming?

               

              Regards,

              Prasanna.A

                • Re: Macro Export PDF Custom File Name & Settings
                  Robert H.

                  HI  Prasanna

                   

                   

                  see the code below for setting up naming convention and exporting to pdf

                   

                  use the to line "SWmoddoc.CustomInfo " to get the required properties from the drawing document  

                   

                   

                  its up to you how you want to format your sheets , the below example should get you going though 

                   

                   

                   

                   

                   

                   

                   

                   

                  'Naming Convention

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

                   

                   

                  PRO_NAME = SWmoddoc.CustomInfo("TITLE")

                   

                   

                  PROJECT_No = SWmoddoc.CustomInfo("PROJECT_No.")

                   

                   

                  ITEM_No = SWmoddoc.CustomInfo("ITEM_No.")

                   

                   

                  DR_TYPE = SWmoddoc.CustomInfo("DR_TYPE")

                   

                   

                  VERSION = SWmoddoc.CustomInfo("VERSION")

                   

                   

                   

                   

                   

                   

                  ' Directory & Naming Convention Config

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

                   

                   

                  NAMCON = (PROJECT_No & "-" & ITEM_No & "-" & DR_TYPE & "_" & PRO_NAME & "_" & "#" & VERSION)

                   

                   

                   

                   

                  ' Copyright Protection

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

                   

                   

                   

                   

                  Dim fso As New Scripting.FileSystemObject

                   

                  If fso.FileExists(Filepath & "PDF\" & NAMCON & ".pdf") Then

                   

                   

                  Dim PDF As String

                   

                   

                  Else

                   

                   

                  swDraw.SaveAs (Filepath & "PDF\" & NAMCON & ".pdf")

                  swDraw.SaveAs (Filepath & "DWG\" & NAMCON & ".dwg")

                    • Re: Macro Export PDF Custom File Name & Settings
                      Prasanna Ashok

                      Hi Robert,

                       

                      Thank you so much for this.

                       

                      Can you please help me to add this into the attached macro?

                       

                      I'm using this macro to convert bulk pdf in a folder.

                       

                      Can you please update this? I just need drawing number_sheet-no_revision number

                       

                      For now, I have only one sheet drawings and i have entered parameters in part custom properties as follows.

                       

                      Drawing No

                      Sheet No

                      Rev No

                       

                      Can you link this three parameters to the output?

                       

                      Regards,

                      Prasanna.A

                        • Re: Macro Export PDF Custom File Name & Settings
                          Robert H.

                          Hi Prasanna

                           

                          Could you send on a sheet with custom properties and part of you file structure, so i can get a better idea of what your asking / doing ?

                           

                          and so that way i can check that this works as intended,

                           

                          Sorry i haven had much time to look though this recently

                           

                          Regards

                           

                          Robert,

                            • Re: Macro Export PDF Custom File Name & Settings
                              Prasanna Ashok

                              Hi Robert,

                               

                              I have attached sample part, drawing and required pdf naming.

                               

                              Example:

                              32559X is the part name. Drawing will be created in the same name as 32559X.

                               

                              When the drawing is converted to PDF (File-->Save as-->PDF), by default, naming will be 32559X.

                              This PDF name should be changed to "Part_number_Revision-number_Sheet-number" format.

                              We enter these parameters as properties inside the part model. See the screenshot in the attachment.

                               

                              So when say File-->Save as-->PDF, the naming should be taken from the model custom properties.

                               

                              Is this possible to do with a macro?

                               

                              Thank you for taking efforts to help me.

                               

                              Regards,

                              Prasanna.A

                                • Re: Macro Export PDF Custom File Name & Settings
                                  Prasanna Ashok

                                  Hi,

                                  Deepak Gupta any help on this?

                                   

                                  In this post, sheet name is included in the naming. Any possibility to get the name from model properties?

                                   

                                  Thank you.

                                   

                                  Regards,

                                  Prasanna.A

                                  • Re: Macro Export PDF Custom File Name & Settings
                                    Robert H.

                                    This might cause you a few issues, are you producing one drawing document per document ?

                                     

                                    are you saving out individual pdf per sheet ?  or one document per model ?

                                     

                                    why is the sheet number in the model properties ?

                                     

                                    i don't understand why you would need to save out the sheet number to the pdf, surely a saving the all the sheets to one pdf is a better option, if not for ease of filling and updating, 

                                     

                                    i don't understand enough to give you a good enough answer,  if produce what your asking for you might end up coming back here, again

                                     

                                    i would rather solve it, first off than ,

                                     

                                    i might not be as complex as i though, although the marco code you posted, seam to make if more complex !

                                     

                                    if it is as simple as saving out a pdf to the same folder of the drawing document then that is very easy you simple grab any of the old pdf marco on this site,  and just 

                                     

                                     

                                    something like this, i think there is one of posted somewhere on here, there is all sort you can do with a marco, the issue is really understanding how to break the problem down, to a machine can handle the boring , or  repetitive bits.

                                     

                                    see bellow,  i think there is a macro of mine hanging about you can use,

                                     

                                    'Naming Convention

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

                                     

                                     

                                    Part_Number = SWmoddoc.CustomInfo("Part Number")

                                     

                                     

                                    Revision = SWmoddoc.CustomInfo("Revision")

                                     

                                     

                                    Sheet_No = SWmoddoc.CustomInfo("Sheet No")

                                     

                                     

                                     

                                     

                                     

                                    ' Directory & Naming Convention Config

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

                                     

                                     

                                    NAMCON = (Part_Number & "_" & Revision & "_" & Sheet_No)

                                     

                                    swDraw.SaveAs (Filepath &  NAMCON & ".pdf")