How do I code it to save the PDF as the current file name?
Following codes will save the current active file as PDF in same location. In case you need to work it for only drawing, check the attached macro.
Dim swApp As SldWorks.SldWorksDim swModel As SldWorks.ModelDoc2Dim Path As StringSub main() Set swApp = Application.SldWorksSet swModel = swApp.ActiveDoc Path = Left(swModel.GetPathName, Len(swModel.GetPathName) - 6) & "PDF" swModel.SaveAs3 "" & Path & "", 0, 0 End Sub
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim Path As String
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Path = Left(swModel.GetPathName, Len(swModel.GetPathName) - 6) & "PDF"
swModel.SaveAs3 "" & Path & "", 0, 0
Thanks Deepak, but I do not want to save the PDF to the same file location as the slddrw location. I need to choose a diffrent location on my local drive. My solidworks drawing files that I would be saving as pdf's is on a network drive.
This is the code I like to use:
Dim swModExt As SldWorks.ModelDocExtension
Dim SwModel As SldWorks.ModelDoc2
Dim OutputPath As String
Dim SubDir As String
Dim RetBool As Boolean
Set swModExt = SwModel.Extension
If Dir(OutputPath & SubDir & SwModel.GetTitle & ".pdf") <> "" Then
Kill OutputPath & SubDir & swModel.GetTitle & ".pdf"
RetBool = swModExt.SaveAs(OutputPath & SubDir & SwModel2.GetTitle & ".pdf", 0, 0, Nothing, Errors, Warnings)
Where OutputPath is the folder and SubDir is any sub-directories within that path.
Will that path be fixed than you can hard code that into the macro else use browse option in macro.
SaveAsPDF with Folder Selection
you can use GetTitle() to get the name of the current file. Depending on your Windows Explorer settings you will get the extension returned also.
Retrieving data ...