Home > Macro > Workgroup PDM Macro 3 – Save out all files & linked files in a Project

Workgroup PDM Macro 3 – Save out all files & linked files in a Project

September 23rd, 2010

In the previous Workgroup PDM Macro, there was a limitation when saving files in a Project, in that linked files were not saved. That was because “PDMWConnection::DocumentList” listed document names for the specified project, and has no option to include referenced/linked files.

The Macro

This macro saves all files including linked files in a particular Project in the PDM Vault, to the local computer.

' Title of Macro: Save all files & linked files 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
    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 = "Project2"
    ' ^ Type in the name of the Project you wish to save the files out of.

    options.SearchCriteria.AddCriteria pdmwOr, pdmwDocumentName, "All", pdmwContains, "sldprt"
    options.SearchCriteria.AddCriteria pdmwOr, pdmwDocumentName, "All", pdmwContains, "slddrw"
    options.SearchCriteria.AddCriteria pdmwOr, pdmwDocumentName, "All", pdmwContains, "sldasm"
    ' ^ set the search query: look for "All" (everything/*) in sldprt,sldasm,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.Save "C:\Temp\"
    Next i
 
    connection.Logout
End Sub

Make sure to scroll to the right in the code area above ^.

If you are having issues or errors make sure you look at the previous two posts with details on using the PDM API #1, #2.

This macro searches for all files in a particular project. It may not be the most efficient macro, but it works, and provides an excellent building block from which to make more intelligent and useful macros. It opens a lot more possibilities of been able to search the Workgroup PDM Vault in a scripted manner and carry out various operations such as saving out files. Again, the SolidWorks Task Scheduler can be set to run this macro periodically. Comments are welcome.

Macro , , ,

  1. No comments yet.
  1. No trackbacks yet.