SolidWorks Save as PDF macro - description and toggle of "View PDF after Saving"
- CarrieIves
- Posts: 163
- Joined: Fri Mar 19, 2021 11:19 am
- Location: Richardson, TX
- x 377
- x 136
SolidWorks Save as PDF macro - description and toggle of "View PDF after Saving"
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?
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?
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?
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"
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
https://help.solidworks.com/2021/englis ... fData.html
Re: SolidWorks Save as PDF macro - description and toggle of "View PDF after Saving"
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.
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.
-
I may not have gone where I intended to go, but I think I have ended up where I needed to be. -Douglas Adams
I may not have gone where I intended to go, but I think I have ended up where I needed to be. -Douglas Adams
- CarrieIves
- Posts: 163
- Joined: Fri Mar 19, 2021 11:19 am
- Location: Richardson, TX
- x 377
- x 136
Re: SolidWorks Save as PDF macro - description and toggle of "View PDF after Saving"
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:
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
So, my macro did use:
Code: Select all
swModel.SaveAs (fullfilename)
It looks like I should be doing something like this:
Code: Select all
boolstatus = swModelDocExt.SaveAs(fullfilename, 0, 0, swExportPDFData, lErrors, lWarnings)
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"
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
In the PDF file name or in PDF document properties?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?
Deepak Gupta
SOLIDWORKS Consultant/Blogger
SOLIDWORKS Consultant/Blogger
Re: SolidWorks Save as PDF macro - description and toggle of "View PDF after Saving"
Have you tried entering swExportData_ExpoprtAllSheets instead of 1?
-
I may not have gone where I intended to go, but I think I have ended up where I needed to be. -Douglas Adams
I may not have gone where I intended to go, but I think I have ended up where I needed to be. -Douglas Adams
- CarrieIves
- Posts: 163
- Joined: Fri Mar 19, 2021 11:19 am
- Location: Richardson, TX
- x 377
- x 136
Re: SolidWorks Save as PDF macro - description and toggle of "View PDF after Saving"
@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.
@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
- CarrieIves
- Posts: 163
- Joined: Fri Mar 19, 2021 11:19 am
- Location: Richardson, TX
- x 377
- x 136
Re: SolidWorks Save as PDF macro - description and toggle of "View PDF after Saving"
@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"
@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.
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.
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.
- CarrieIves
- Posts: 163
- Joined: Fri Mar 19, 2021 11:19 am
- Location: Richardson, TX
- x 377
- x 136
Re: SolidWorks Save as PDF macro - description and toggle of "View PDF after Saving"
@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.
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.