Create Presentation Studio PDF (VBA)
This example shows how to create a SolidWorks Presentation Studio PDF file.
'------------------------------------------
'
'
' Preconditions:
'
' 1. C:\temp folder exists.
' 2. The theme, C:\Program Files\SolidWorks Corp\SolidWorks\data\themes\red\theme.xml, exists.
' 3. Open C:\Program Files\SolidWorks Corp\SolidWorks\samples\tutorial\routing-pipes\fittings\ReducerRoute.sldasm
' and create a named view called DownView.
' 4. Run the macro.
'
' Postconditions:
' 1. C:\temp\MyPresentation.pdf is created and
' includes the active, back, trimetric, and DownView
' views.
' 2. Close the PDF file.
'
' NOTE: Because this assembly document is used by a
' SolidWorks tutorial, do not save it when
' when closing it.
'
'------------------------------------------
Option Explicit
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swModelDocExt As SldWorks.ModelDocExtension
Dim pdfFile As String
Dim themeXML As String
Dim textNamedViewArray(0) As String
Dim textNameArray(2) As String
Dim textArray(2) As String
Dim presentationOpts As Long
Sub main()
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swModelDocExt = swModel.Extension
' Set name of PDF file, presentation theme XML file,
' presentation standard view options, and name of the user-created name view
pdfFile = "C:\temp\MyPresentation.pdf"
themeXML = "C:\Program Files\SolidWorks Corp\SolidWorks\data\themes\red\theme.xml"
' Examine the template's theme.xml
' to determine if textNameArray must be set;
' i.e., each text_area XML element must be have
' a corresponding textNameArray array element
textNameArray(0) = "Title"
textNameArray(1) = "Summary"
textNameArray(2) = "Description"
textArray(0) = "My Presentation"
textArray(1) = "My part"
textArray(2) = "My PDF"
' You must specify swPresentationOpts_Pres and
' any other standard views you want to include
' in your presentation
presentationOpts = (swPresentationOpts_Pres + swPresentationOpts_BackView + swPresentationOpts_TrimetricView)
' User-created named view to include in presentation
textNamedViewArray(0) = "DownView"
' Create presentation
swModelDocExt.CreatePresentation2 pdfFile, themeXML, presentationOpts, textNamedViewArray, textNameArray, textArray
' Deselect component
swModel.ClearSelection2 True
End Sub