Home > Macro > Workgroup PDM Macro 2 – Save out all files in a Project

Workgroup PDM Macro 2 – Save out all files in a Project

September 23rd, 2010

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.

The Macro

' 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
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.

Linked files will not be saved.

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.

IntelliSense Code completion helps make sure you are referencing the PDM API correctly

Macro , , ,

  1. Immow
    September 10th, 2012 at 14:13 | #1

    I can’t thank you enough this tutorial helped me a lot. I modified the code so that I download files from several projects (we have sub projects) in their desired folders. Also created a folder check if they don’t exist create them 😀

    This was all made possible to your wonderful tutorial!

    Thank you.

  2. Matt Martens
    August 22nd, 2013 at 16:34 | #2

    This macro works great! I modified it to go through all folders in the vault. The company i worked for uses it in conjunction with task scheduler to update a pdf directory with most recent versions of drawings for the sales & manufacturing teams.


  1. September 23rd, 2010 at 19:02 | #1