Workgroup PDM Macro 2 – Save out all files in a Project
So the previous post showed how a single file can be saved from Workgroup PDM onto your local computer using a macro. This macro builds upon that. If you are starting out with macros, I suggest you go back and get that working first.
' Title of Macro: Save all files out from a Project in Workgroup PDM ' 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 ' ^ remove the single quote from above if you want to debug. Set alldocs = connection.Documents project = connection.DocumentList("Project1") ' ^ Type in the name of the Project you wish to save the files out of. For Each item In project 'msg = MsgBox(item, vbCritical) ' ^ remove the single quote from above if you want to debug. Set doc = alldocs(item) doc.Save "C:\Temp\" Next item connection.Logout End Sub
This macro uses connection.DocumentList(“Projectname”) to create an array of files contained in a particular project in the PDM Vault. To debug this macro further, uncomment the lines “Dim msg” and “msg = MsgBox(item, vbCritical)”, and when you run the macro you will get a pop-up dialog telling you the names of each of the files found in the PDM Project.
There is one cavet. If you have links / references in the Project you are saving, those linked files will not be saved. E.g. in the image below, the Car-and-Engine-Drawing and the Slide3 files will not be saved out. I will post a following macro which will be able to save linked files.
I’m not going to provide a download of this Macro. I recommend that you create a new Macro in SolidWorks, and type (or copy and paste) the above code into the new empty macro. Also, in case you have not read the previous macro, make sure to add in “SolidWorks Workgroup PDM 1.0 Type Library” under Tools -> References in Microsoft Visual Basic. That way you can use “IntelliSense” (code prompt and completion) to make sure that the pdm parameters are referenced correctly. In the image below, after typing the . (period/full stop), a drop-down list of available parameters should show up. If the drop-down list doesn’t show up, something is wrong. Check Tools -> References and go from there.