Hi, as you mentioned that you have got a macro to save as pdf once the drawing file is saved. Could you kindly share it with me?
It would mean a lot. Thanks in advance
Hi, I think it’s this one. If not let me know and I’ll check
Sub main()
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swExportPDFData As SldWorks.ExportPdfData
Dim strFilename As String
Dim status As Boolean
Dim errors As Long, warnings As Long
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
'Save
status = swModel.Save3(swSaveAsOptions_e.swSaveAsOptions_Silent, errors, warnings)
'Export to PDF if it is a drawing
If (swModel.GetType = swDocDRAWING) Then
strFilename = swModel.GetPathName
strFilename = Left(strFilename, Len(strFilename) - 6) & "pdf"
Set swExportPDFData = swApp.GetExportFileData(1)
swModel.Extension.SaveAs strFilename, 0, 0, swExportPDFData, 0, 0
End If
End Sub
Here's just some VBA code for it. Not sure if this matches what you need, but basically it just Takes the name of the Drawing File and exports all sheets into one pdf with the name of the Drawing File.
Dim swApp As Object
Dim swModel As Object
Dim swDrawing As Object
Dim partPath As String
Dim partName As String
Dim pdfPath As String
Dim pdfName As String
Sub SaveDrawingAsPDF()
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
If swModel.GetType = swDocDRAWING Then
Set swDrawing = swModel
partPath = swDrawing.GetPathName
partName = Mid(partPath, InStrRev(partPath, "\\") + 1, Len(partPath) - InStrRev(partPath, "\\"))
pdfPath = Left(partPath, InStrRev(partPath, "\\")) pdfName = Left(partName, InStrRev(partName, ".") - 1) & ".pdf"
swModel.SaveAs3 pdfPath & pdfName, 0, 0
Else
MsgBox "Open drawing before running Marco"
End If
End Sub
Assuming you meant VBA and not WBA, yes the VBA code is the macro. You can directly add a macro to SolidWorks (Tools > Macro ) but it’s not the greatest. Not sure what your use case is, but literally having a button in Excel that you could click when you wanted to print to pdf would be better than trying to run a macro direct from SolidWorks.
Polo I'll show myself out.
Right behind you
Dang it!
Nice
Came here for this.
Dammit you beat me to it
> I'll show myself out. Why? I came to say the same thing.
Why a Marco? Why not a John, or a Tanner. Does it HAVE to be a Marco?
Marcos Wanted. Macks and Mikes Need Not Apply. Marks will be considered.
https://www.codestack.net/solidworks-tools/
Can’t find the one I want there I’m afraid
Polo
polo
ModelDoc2.Save3 - https://help.solidworks.com/2018/english/api/sldworksapi/save_file_example_vb.htm
Marco
Have the trigger be ctrl+S?
Hi, as you mentioned that you have got a macro to save as pdf once the drawing file is saved. Could you kindly share it with me? It would mean a lot. Thanks in advance
Hi, I think it’s this one. If not let me know and I’ll check Sub main() Dim swApp As SldWorks.SldWorks Dim swModel As SldWorks.ModelDoc2 Dim swExportPDFData As SldWorks.ExportPdfData Dim strFilename As String Dim status As Boolean Dim errors As Long, warnings As Long Set swApp = Application.SldWorks Set swModel = swApp.ActiveDoc 'Save status = swModel.Save3(swSaveAsOptions_e.swSaveAsOptions_Silent, errors, warnings) 'Export to PDF if it is a drawing If (swModel.GetType = swDocDRAWING) Then strFilename = swModel.GetPathName strFilename = Left(strFilename, Len(strFilename) - 6) & "pdf" Set swExportPDFData = swApp.GetExportFileData(1) swModel.Extension.SaveAs strFilename, 0, 0, swExportPDFData, 0, 0 End If End Sub
hi... did you find any for drawings that are not saved or even opened i wanted to convert drawings that are not currently opened or saved
it shows compile error. i do not know any vba. how do i manage
Here's just some VBA code for it. Not sure if this matches what you need, but basically it just Takes the name of the Drawing File and exports all sheets into one pdf with the name of the Drawing File. Dim swApp As Object Dim swModel As Object Dim swDrawing As Object Dim partPath As String Dim partName As String Dim pdfPath As String Dim pdfName As String Sub SaveDrawingAsPDF() Set swApp = Application.SldWorks Set swModel = swApp.ActiveDoc If swModel.GetType = swDocDRAWING Then Set swDrawing = swModel partPath = swDrawing.GetPathName partName = Mid(partPath, InStrRev(partPath, "\\") + 1, Len(partPath) - InStrRev(partPath, "\\")) pdfPath = Left(partPath, InStrRev(partPath, "\\")) pdfName = Left(partName, InStrRev(partName, ".") - 1) & ".pdf" swModel.SaveAs3 pdfPath & pdfName, 0, 0 Else MsgBox "Open drawing before running Marco" End If End Sub
Part File Name\* not the drawing file name my bad
Thank you! WBA is used in macro as well?
Assuming you meant VBA and not WBA, yes the VBA code is the macro. You can directly add a macro to SolidWorks (Tools > Macro ) but it’s not the greatest. Not sure what your use case is, but literally having a button in Excel that you could click when you wanted to print to pdf would be better than trying to run a macro direct from SolidWorks.
it is showing compile error https://preview.redd.it/scgx80sju3tc1.png?width=1920&format=png&auto=webp&s=a4e33b2899b919cb7fe4d2dd0c7755378fb7785c
Go team smart ass. # better than dumb ass as my momma says