How to save to PDF with a macro

Hi all

here is my problem, I would like to save in PDF the drawings I modify.

As I have to do several in a row, each time I have to save under re-give the way...... in short, a lot of clicks.

I tried to make a macro, it saves in PDF, but still in its creation folder, and not in the same folder as the drawing.

The macro in question:

' ******************************************************************************
' C:\Users\FCH. CORADINCORP.001\AppData\Local\Temp\swx3264\Macro1.swb - macro recorded on 03/30/16 by fch
' ******************************************************************************
Dim swApp As Object

Dim Part As Object
Dim boolstatus As Boolean
Dim longstatus As Long, longwarnings As Long

Sub main()

Set swApp = _
Application.SldWorks

Set Part = swApp.ActiveDoc
longstatus = Part.SaveAs3("E:\teste macro.PDF", 0, 0)
End Sub

 

thank you for your help

Francis


enr-pdf-1.swp

Why not use batchconverter?....

 

1 Like

Hello

Here's a macro that should work:

 


Dim swApp As Object

Dim Part As Object
Dim boolstatus As Boolean
Dim docPath
Dim longstatus As Long, longwarnings As Long

Sub main()

Set swApp = _
Application.SldWorks

 

Set Part = swApp.ActiveDoc
docPath = Part.GetPathName
longstatus = Part.SaveAs3(Replace(LCase(docPath), ".slddrw", ".pdf"), 0, 0)
End Sub

5 Likes

Hello, use the Mycadtools utility

2 Likes

Hello

Here is the MOCRO we use at home, this macro saves the PDF automatically in the folder where the drawing is located.


macro_pdf.swp
1 Like

Thank you all for your help

SergeR:   I don't know bathconvert, but I'll find out.

amseli:   Mycad tool I don't have it in my contract at the moment. I hope for soon.

Manu 67:  thank you manu but your macro is empty

 

 .PL: thank you for the macro, I just replaced the .sldprt with slddrw and now it works very well, thank you again

the original line: longstatus = Part.SaveAs3(Replace(LCase(docPath), ".sldprt", ".pdf"), 0, 0)

replace with: longstatus = Part.SaveAs3(Replace(LCase(docPath), ".slddrw", ".pdf"), 0, 0)

Thank you again to all for your help

Francis

1 Like

Dim swApp As SldWorks.SldWorks
Dim swModel As ModelDoc2
Dim lErrors As Long
Dim lWarnings As Long

Sub main()

Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
swModel.Extension.SaveAs GetFilename(swModel.GetPathName) & " rev." & swModel.GetCustomInfoValue("", "Revision") & ".pdf", swSaveAsCurrentVersion, swSaveAsOptions_Silent, Nothing, lErrors, lWarnings

End Sub


Function GetFilename(strPath As String) As String
    Dim strTemp As String
    strTemp = Mid$(strPath, InStrRev(strPath, "\") + 1)
    GetFilename = Left$(strTemp, InStrRev(strTemp, ".") - 1)
End Function

 


macro_pdf.docx
1 Like

Thank you manu67 I'll try your macro as soon as possible

Hello

Here's the one that works and I just tested it:

Dim swApp As SldWorks.SldWorks
Dim swModel As ModelDoc2
Dim lErrors As Long
Dim lWarnings As Long

Sub main()

Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
swModel.Extension.SaveAs GetFilename(swModel.GetPathName) & " rev." & swModel.GetCustomInfoValue("", "Revision") & ".pdf", swSaveAsCurrentVersion, swSaveAsOptions_Silent, Nothing, lErrors, lWarnings

End Sub

Function GetFilename(strPath As String) As String
Dim strTemp As String
strTemp = Mid$(strPath, InStrRev(strPath, "\") + 1)
GetFilename = Left$(strTemp, InStrRev(strTemp, ".") - 1)
End Function

3 Likes

Macros work well, but I have a small request to add if it's possible that the macro works for all plans open in Solidworks.