-
Re: API to save as PDF to network folder
Paul Marsman Jun 8, 2010 11:17 AM (in response to Tony Hayes)Yes, it is possible.
-
Re: API to save as PDF to network folder
Paul Marsman Jun 8, 2010 11:31 AM (in response to Tony Hayes)look at these save events for drawings:
DDrawingDocEvents_FileSavePostNotifyEventHandler
DDrawingDocEvents_FileSaveNotifyEventHandler
-
Re: API to save as PDF to network folder
Tony Hayes Jun 8, 2010 11:33 AM (in response to Paul Marsman)Would anyone have a sample of something like this?
-
Re: API to save as PDF to network folder
Paul Marsman Jun 8, 2010 11:38 AM (in response to Tony Hayes)here is my macro for saving a drawing to pdf in the same folder as the pdf. The filename works for us since we don't have "." in our filenames, if that is not the case for you then some modification will be required. Also, if you are always saving to the same folder you can hardcode that pretty easy. The only thing is this doesn't have the save event in it... I've never done an event for SolidWorks but it isn't hard to do in Excel and such. If you need help with that let me know.
-----------------------
' ******************************************************************************
' This Macro will save the active drawing sheet as a PDF file in the same directory
' ******************************************************************************Dim swApp As SldWorks.SldWorks
Dim swDrawing As DrawingDoc
Dim swModExtension As ModelDocExtension
Dim swExportData As ExportPdfData
Dim sheetsFileNames As Variant
Dim sheetsFileName As Variant
Dim lWarnings As Long
Dim lErrors As Long
Dim sFileName As String
Dim strings As VariantSub SavePDF()
Set swApp = Application.SldWorks
Set swDrawing = swApp.ActiveDoc
Set swModExtension = swDrawing.ExtensionIf swDrawing Is Nothing Then
MsgBox ("Drawing must be open")
Exit Sub
End IfsFileName = swDrawing.GetPathName() 'Gets file sFileName with path
If sFileName = "" Then
MsgBox ("Please save the drawing before PDF export")
Exit Sub
Else
strings = Split(sFileName, ".")
sFileName = strings(0) & ".PDF"
End If
'MsgBox (sFileName)Set swExportData = swApp.GetExportFileData(swExportDataFileType_e.swExportPdfData)
boolstatus = swExportData.SetSheets(swExportDataSheetsToExport_e.swExportData_ExportCurrentSheet, Nothing)
'boolstatus = swExportData.SetSheets(swExportDataSheetsToExport_e.swExportData_ExportAllSheets, 1)'save the file
boolstatus = swModExtension.SaveAs(sFileName, swSaveAsVersion_e.swSaveAsCurrentVersion, swSaveAsOptions_e.swSaveAsOptions_Silent, Nothing, 0, 0)If boolstatus Then
MsgBox "PDF Saved"
Else
MsgBox "Save as PDF failed, Error code:" & lErrors
End If
Set swApp = Nothing
Set swmodel = Nothing
Set swModelDocExt = Nothing
Set swExportData = Nothing
End Sub-
Re: API to save as PDF to network folder
Tony Hayes Jun 8, 2010 12:54 PM (in response to Paul Marsman)Will this work when you save the file or will the users have to run this macro? Also our file nemaes doe have a "." in them so what owuld I need to change? Another thing can this be used to save to a different location then the current folder?
-
Re: API to save as PDF to network folder
Matthew Lorono Jun 8, 2010 3:33 PM (in response to Tony Hayes)I've made a macro that lets the user pick whereever they want to save on-the-fly, with adjustable defaults (within the code): SaveToPDF with Folder Selection
Matt Lorono
-
Re: API to save as PDF to network folder
Tony Hayes Jun 8, 2010 3:59 PM (in response to Matthew Lorono)This macro works but the user as to run it. I am hoping for something that saves a PDF without having a second operation. If they have to run this marco it is no differenent then doing a save as PDF. I am hoping for something that wil save it as a PDF when they save the drawing file.
-
Re: API to save as PDF to network folder
Matthew Lorono Jun 9, 2010 11:55 AM (in response to Tony Hayes)You can use this or any other similar macro and add one or two lines to get exactly what you want, then assign the macro to a toolbar button.
Matt Lorono
-
Re: API to save as PDF to network folder
Michael De Jager Oct 17, 2013 10:09 AM (in response to Tony Hayes)I think I am at the same point that you were at, when you wrote your post. Did you work out how to make a macro execute automatically at the time a document is saved, without any additional input from the user?
-
Re: API to save as PDF to network folder
Deepak Gupta Oct 18, 2013 2:10 AM (in response to Michael De Jager)Michael try the attached macro made by modifying the macro by Wayne Matus (https://forum.solidworks.com/message/88655#88655)
The macro will create a PDF file of the active file when file is saved. The macro works only for existing file, so in case there is a new file you would have to save twice to make the PDF. The PDF file will be created in the same location with active SolidWorks file name.
You need to run the macro after opening SW and macro will continue to run in the background. Setting can be done to make sure that this macro automatically runs whenever SolidWorks is run. Also the path can be changed to any other location too.
You might also find this post helpful for your future reference.
-
Make PDF on File Save.swp.zip 16.3 KB
-
Re: API to save as PDF to network folder
Michael De Jager Oct 18, 2013 5:52 AM (in response to Deepak Gupta)Thank you Deepak. I appreciate your help and also the useful post for new members. In my defence, I am so new to this environment that it is hard to know the correct terminology. I am just doing an assessment of the work involved and dont have a useful depth of understanding of the product yet.
Having said that, would you mind pointing me to the right area of the system or documentation to learn about how a "Setting can be done to make sure that this macro automatically runs whenever SolidWorks is run"?
Thanks again.
-
Re: API to save as PDF to network folder
Deepak Gupta Oct 18, 2013 6:20 AM (in response to Michael De Jager)You're always welcome Michael. The method to run a macro on SolidWorks startup is easy.
You'll have simply modify the target for the SolidWorks shortcut on the desktop. I would suggest you to create a new shortcut for this macro and rename that shortcut some meaningful so that in case you need to have this macro running in background or startup, you can use the other shortcut for running SW.
- Right click on the SolidWorks shortcut on the desktop.
- In the target line, adding a space then "/m".
- Then another space and "macro complete path"
Example: "C:\Program Files\SolidWorks\SLDWORKS.exe" "/m" "C:\Test\Make PDF on File Save.swp" (the SW installation path may be different on your machine)
P.S. The quotes are very important, so you may copy and paste "/m" "C:\Test\Make PDF on File Save.swp" and change the macro path.
-
Re: API to save as PDF to network folder
Michael De Jager Oct 18, 2013 7:04 AM (in response to Deepak Gupta)Wonderful. Thanks :-)
-
Re: API to save as PDF to network folder
David Brill Feb 13, 2017 9:31 AM (in response to Deepak Gupta)Sorry to revive a very old thread, but I've been trying to get this to work all day. The issue I'm having is with the actual macro. When I run it, it does nothing and saving drawings does not produce the required PDFs. I suspect it might have something to do with the code being a little out of date to run on Solidworks 2017, but I don't have the necessary expertise to confirm or solve this.
Any help would be greatly appreciated
-
Re: API to save as PDF to network folder
Deepak Gupta Feb 13, 2017 9:39 AM (in response to David Brill)David, make sure you run the macro before having any file open. And then try again.
-
Re: API to save as PDF to network folder
David Brill Feb 13, 2017 10:01 AM (in response to Deepak Gupta)Deepak Gupta thank you for the speedy response. That worked like a charm!
However I don't understand why the shortcut isn't working. As you said that should automatically make Solidworks save PDFs on start up without having to run the macro manually.
I have set the "Start in:" location to: "C:\Program Files\SOLIDWORKS Corp\SOLIDWORKS (3)\" "/m" "C:\Users\Joshua\Downloads\Make PDF on File Save\Make PDF on File Save.swp"
-
Re: API to save as PDF to network folder
Deepak Gupta Feb 13, 2017 10:41 AM (in response to David Brill)David Brill wrote:
However I don't understand why the shortcut isn't working. As you said that should automatically make Solidworks save PDFs on start up without having to run the macro manually.
I have set the "Start in:" location to: "C:\Program Files\SOLIDWORKS Corp\SOLIDWORKS (3)\" "/m" "C:\Users\Joshua\Downloads\Make PDF on File Save\Make PDF on File Save.swp"
Let me check that on SW2017 and report back.
-
Re: API to save as PDF to network folder
David Brill Feb 14, 2017 6:25 AM (in response to Deepak Gupta)Thanks Deepak Gupta
-
Re: API to save as PDF to network folder
David Brill Feb 17, 2017 7:35 AM (in response to Deepak Gupta)Deepak Gupta any luck? I've tried updating to SP2, but it hasn't helped.
-
Re: API to save as PDF to network folder
Deepak Gupta Feb 18, 2017 8:38 AM (in response to David Brill)David, you need to create a new shortcut and not the one created by default. Go to the SOLIDWORKS installation folder, right click on SLDWORKS.exe and create a new shortcut. And then change the target line.
-
Re: API to save as PDF to network folder
David Brill Feb 21, 2017 8:23 AM (in response to Deepak Gupta)Thank you Deepak Gupta, that worked!
Really appreciate all your help!
-
-
-
-
-
-
Re: API to save as PDF to network folder
Jesse Seger Feb 13, 2017 9:47 AM (in response to David Brill)We've created a tool that will allow you to run any macro on certain events such as file save, rebuild, document open, and file close. Just point it to your macro and set it up. Here is a link to the free download.
-
-
-
-
-
-
-
-
-
-