Workgroup PDM Macro 4 – Export PDFs of Drawings in a Project
Again in this series of Workgroup PDM Macros, this one builds upon the previous. It’s actually nearly identical, but instead of going “doc.Save”, we go “doc.SaveAsPDF”.
The Macro
This macro saves/exports the PDF of all Drawings in a Project in the PDM Vault onto a local computer.
' Title of Macro: Save/Export PDFs from all Drawings in a Workgroup PDM Project ' Further info: http://solidworks.burkesys.com/category/macro/ ' Author: Stephen Burke | www.sburke.eu ' Version: SolidWorks 2010 ' Add in "SolidWorks Workgroup PDM 1.0 Type Library" under: Tools - References ' Date: 23/09/2010 Option Explicit Dim swApp As Object Sub main() Dim connection As PDMWConnection Set connection = CreateObject("PDMWorks.PDMWConnection") connection.Login "pdmwadmin", "pdmwadmin", "localhost" 'Enter your PDM Login details above, "username", "password", "pdmserver" Dim alldocs As PDMWDocuments Dim doc As PDMWDocument Dim project Dim item Dim msg Dim filename Set alldocs = connection.Documents Dim options As PDMWorks.PDMWSearchOptions Dim criteria As PDMWorks.PDMWSearchCriteria Dim results As PDMWorks.PDMWSearchResults Dim result As PDMWorks.PDMWSearchResult Dim i Dim cnt Set options = connection.GetSearchOptionsObject options.SearchOnlyChildrenOf = "Project1" ' ^ Type in the name of the Project you wish to save the files out of. options.SearchCriteria.AddCriteria pdmwOr, pdmwDocumentName, "All", pdmwContains, "slddrw" ' ^ set the search query: look for "All" (everything/*) in slddrw. Set results = connection.Search(options) cnt = results.Count For i = 0 To cnt - 1 Set result = results(i) 'msg = MsgBox(result.Name, vbCritical) Set doc = alldocs(result.Name) doc.SaveAsPDF "C:\Temp\" 'filename = "C:\Temp\" & Replace(result.Name, ".SLDDRW", " ") & result.Revision & ".pdf" 'If Dir(filename) <> "" Then Kill filename 'Name "C:\Temp\" & result.Name & ".pdf" As filename ''Uncomment the above 3 lines. This will output the file "drawing 01.pdf", where 01 is the current revision of the drawing. Next i connection.Logout End Sub
Make sure to scroll to the right in the code area above ^. Link to Macro Download
Note: The default filename which will be created is “filename.SLDDRW.pdf”. I read on the SolidWorks Forums of a person requesting an output file name: “filename 01.pdf” where 01 is the current revision. This functionality is in the above code. Uncomment the 3 lines underneath “doc.SaveAsPDF” (do so by removing the single quotation mark ‘ ). This is quite nice, because if this macro was being run by the Task Scheduler every night, it would be evident from looking at C:\Temp (or outbox folder specified) that a new revision is available.
Readme
New in SolidWorks 2008 was the option to automatically have PDM create a PDF for every drawing upon check-in. This macro saves/exports this PDF, and is much quicker than if we were to re-print a PDF. If however, the option to create PDFs on check-in is not set in the Vault Admin Tool, this Macro will not work. See image below for where this option is within the VaultAdmin Tool.
If this setting was not turned on, and you just enabled it, this macro still won’t work. The PDF only gets created upon check-in of drawings after this above setting is enabled. To check to see if a PDF is available for drawings in the Vault, right-click on a Drawing and see if the option “View Document as PDF” is available (see image below). If this method works, then the macro should too. If a drawing does not have a PDF, you may get the error “An unknown filesystem error occurred. (50)”. In this case, set the above option, checkout and checkin the drawing to have the PDF created automatically.
Cautionary Warning
While macros are very powerful and can perform a lot of tasks in a short space of time, you need to be very careful. Manually, the PDFs exported, need to be checked by hand, individually, to make sure the contents are correct and accurate. A disaster can occur if someone runs the above macro and sends them off to manufacture, but never checks to see if the exported PDFs are correct and accurate. Check and check again. Unfortunately issues for whatever reason can occur, and its not enough just to say “it should have worked, its not my fault, I just ran the macro and emailed the pdfs”. Manual checking of the actions carried out by the macro must be done.