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?
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:
swModel.SaveAs (fullfilename)
fullfilename is derived from properties in the model and placed in a specific folder
It looks like I should be doing something like this:
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.
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 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.
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.
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.