Page 1 of 1
SolidWorks Save as PDF macro - description and toggle of "View PDF after Saving"
Posted: Mon Dec 04, 2023 12:29 pm
by CarrieIves
We have a Save as PDF macro we run from SolidWorks.
If I were to manually save as PDF, I can adjust the check box "View PDF after saving". Is there an API call for SolidWorks that can toggle this?
- image.png (8.27 KiB) Viewed 2208 times
Also, the description property from SolidWorks shows here. I don't know that the information gets saved into the PDF. Can we include that information in the PDF?
Re: SolidWorks Save as PDF macro - description and toggle of "View PDF after Saving"
Posted: Mon Dec 04, 2023 12:38 pm
by AlexB
Take a look at this interface. It allows you to set the "View after save" option for PDFs.
https://help.solidworks.com/2021/englis ... fData.html
Re: SolidWorks Save as PDF macro - description and toggle of "View PDF after Saving"
Posted: Mon Dec 04, 2023 12:59 pm
by SPerman
My "Save as PDF" macro uses the "SaveAs3" method. This appears to be a rather generic "Save As" where the output is based on the file extension.
There is, however, a different method that deals specifically with PDF's and allows you to set the above mentioned switch.
https://help.solidworks.com/2023/englis ... 77a130#Pg0
It looks like AlexB beat me to it.
Re: SolidWorks Save as PDF macro - description and toggle of "View PDF after Saving"
Posted: Tue Dec 05, 2023 12:12 pm
by CarrieIves
So, I have been trying to rework my regular save as PDF macro (not what is used as a PDM task) to follow the example. I want to always save all sheets. The number of sheets varies by drawing.
So, my macro did use:
fullfilename is derived from properties in the model and placed in a specific folder
It looks like I should be doing something like this:
Code: Select all
boolstatus = swModelDocExt.SaveAs(fullfilename, 0, 0, swExportPDFData, lErrors, lWarnings)
What I'm not getting right is the swExportPDFData. Which I think is supposed to be the sheets we want to export.
From the help here:
https://help.solidworks.com/2023/englis ... ort_e.html
So, I tried putting in 1 to get all sheets exported but got an error "Type mis-match"
The examples I have seen look like they are putting the sheets into an array, but the examples I am looking at are not clear.
Thanks,
Carrie
Re: SolidWorks Save as PDF macro - description and toggle of "View PDF after Saving"
Posted: Tue Dec 05, 2023 12:40 pm
by gupta9665
Add the below line above
boolstatus = swModelDocExt.SaveAs(Full File Name Here with extension, 0, 0, swExportPdfData, lErrors, lWarnings)
Dim swExportData As SldWorks.ExportPdfData
Set swExportData = swApp.GetExportFileData(swExportPdfData)
swExportData.ViewPdfAfterSaving = False
CarrieIves wrote: ↑Mon Dec 04, 2023 12:29 pm
Also, the description property from SolidWorks shows here. I don't know that the information gets saved into the PDF. Can we include that information in the PDF?
In the PDF file name or in PDF document properties?
Re: SolidWorks Save as PDF macro - description and toggle of "View PDF after Saving"
Posted: Tue Dec 05, 2023 12:44 pm
by SPerman
Have you tried entering swExportData_ExpoprtAllSheets instead of 1?
Re: SolidWorks Save as PDF macro - description and toggle of "View PDF after Saving"
Posted: Tue Dec 05, 2023 1:25 pm
by CarrieIves
@SPerman - I tried your suggestion of entering swExportData_ExpoprtAllSheets instead of 1. I got runtime error '424' "Object required"
@gupta9665 - I updated my macro to what I think you suggested and got error '438' "Object doesn't support this property or method" in the Set swExportData line. Here's the snippet from that part of the macro.
Code: Select all
If savefile Then
Dim swExportData As SldWorks.ExportPdfData
Set swExportData = swApp.GetExportFileData(swExportPDFData)
swExportData.ViewPdfAfterSaving = False
boolstatus = swModelDocExt.SaveAs(fullfilename, 0, 0, swExportData_ExpoprtAllSheets, lErrors, lWarnings)
SHAddToRecentDocs Path, fullfilename
End If
Re: SolidWorks Save as PDF macro - description and toggle of "View PDF after Saving"
Posted: Tue Dec 05, 2023 1:46 pm
by CarrieIves
@gupta9665 It would be nice to save the SolidWorks properties into the PDF, but I'm not sure how to see the PDF properties.
Re: SolidWorks Save as PDF macro - description and toggle of "View PDF after Saving"
Posted: Tue Dec 05, 2023 2:04 pm
by AlexB
@CarrieIves here's a minimal example of what to do to export your sheets. If you are specifying sheet names then un-comment the lines that have vSheets in it.
Code: Select all
Option Explicit
Dim swApp As SldWorks.SldWorks
Sub main()
Dim swModel As ModelDoc2
Dim swDraw As DrawingDoc
Dim swModelDocExt As ModelDocExtension
Dim boolStatus As Boolean
Dim lErrors As Long
Dim lWarnings As Long
'Dim vSheets As Variant
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swDraw = swModel
Set swModelDocExt = swModel.Extension
Dim swExportPDFData As ExportPdfData
Set swExportPDFData = swApp.GetExportFileData(swExportDataFileType_e.swExportPDFData) 'Argument is integer 1
'vSheets = swDraw.GetSheetNames
swExportPDFData.ViewPdfAfterSaving = False
'boolStatus = swExportPDFData.SetSheets(swExportDataSheetsToExport_e.swExportData_ExportSpecifiedSheets, vSheets)
'Debug.Print boolStatus
boolStatus = swModelDocExt.SaveAs(Environ("USERPROFILE") & "\Desktop\test.pdf", 0, 0, swExportPDFData, lErrors, lWarnings)
Debug.Print boolStatus & " " & lErrors & " " & lWarnings
End Sub
Edit: To answer your question about variables on your PDF file. Since you're on PDM Standard, your best bet of setting these yourself is to get creative with Dispatch since you don't have access to the PDM API. This assumes that Dispatch is available with PDM Standard but I can't recall right now if that's the case.
Re: SolidWorks Save as PDF macro - description and toggle of "View PDF after Saving"
Posted: Tue Dec 05, 2023 3:44 pm
by CarrieIves
@AlexB Thank you for the example. I don't know what I had wrong in my macro, but was able to finally step through and get it to line up with what you provided (with my filename and location adjustments)
What I am thinking of doing, is having all our users uncheck the "View PDF after saving" check box. For the PDFs that we make using the macro, I can have it set to view the PDF.
Though, I am pushing back some to my VAR.