Posts Tagged ‘workgroup pdm’

Workgroup PDM Macro 1 – Save out a single file onto your computer

September 23rd, 2010

Skip straight to the Macro >


Macros in SolidWorks are extremely powerful and useful. They can be however difficult to maintain, especially when upgrading to new versions of SW and requires a good knowledge of SW API and VB/C++. There are also many macros available for SolidWorks, (lenny’s SW Macros, 3D ContentCentral Macros, Loronos SW Macro Downloads, SolidWorks Forums – login required, and SolidWorks API Examples – broken, even when logged in) which are particularly helpful to study and use as a foundation to build your own macro. Unfortunately there are very few macros available for Workgroup PDM and some of which seem to get lost, especially links on the SolidWorks website (the sample pdm api project on the main solidworks help website is broken – FAIL). Also most of the active work regarding managing SW data is going towards SolidWorks Enterprise PDM which sits on a SQL server as opposed to a file based DB with Workgroup PDM.

SolidWorks Workgroup PDM is a product that comes with SolidWorks Professional and SolidWorks Premium. It allows for revision control of SolidWorks files, and allows multiple people to work on the same SolidWorks project. All SolidWorks files (and other files such as DWG, doc, jpg) gets stored in a main Vault on a central server. There is no direct access to files in the PDM Vault. Access must be through either SolidWorks or SolidWorks Explorer with a PDM Add-In. Files in the vault cannot be accessed directly via Windows Network Share/SMB. As a result interaction with data in Workgroup PDM must be done manually. However here is where SolidWorks Macros and the PDM API comes in.

This macro is the first of a few that I am going to write on Workgroup PDM. If your beginning to write macros, I’d recommend starting with this Macro which is a good foundation.

The Macro

This macro allows a user to copy/save a single specified file from the PDM Vault onto their computer.
While this is quite a small task, it is an excellent beginning to learn the SolidWorks PDM API.

Download Zip file of the Macro >

' Title of Macro: Save a single file out from the Workgroup PDM Vault
' Further info:
' Author: Stephen Burke |
' Version: SolidWorks 2010
' Instructions: Replace "123456.SLDDRW", with the file required.
' 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
    Set alldocs = connection.Documents
    Set doc = alldocs("123456.SLDDRW")
    ' ^ Type in the name of the file you wish to save out.
    doc.Save "C:\Temp\"
    ' ^ Type in a folder on your computer to save into.

End Sub
Readme / Usage
  1. Open SolidWorks
  2. Tools -> Macro -> Edit (browse to the saved Zip file)
  3. (in Microsoft Visual basic) Tools -> References -> (add-in) “SolidWorks Workgroup PDM 1.0 Type Library”
  4. (in Microsoft Visual basic) Click the Save icon and close down the Visual Basic Editor
  5. (in SolidWorks) Tools -> Macro -> Run
  6. Check C:\Temp for the file

Troubleshooting & FAQ’s

Problem: You receive the following error: “Compile error: Can’t find project or library”
Solution: Go to Tools -> References and add in “SolidWorks Workgroup PDM 1.0 Type Library”. If that does not work, then go to SolidWorks, Tools -> Macro -> New. Choose a new name for the macro and where to save it. This will open up a new Macro. Go to Tools -> References and add in “SolidWorks Workgroup PDM 1.0 Type Library”. Then copy and paste the code from above.

Problem: You receive the following error: “Method ‘Item’ of object ‘IPDMWDocuments’ failed”.
Solution: The file you require was misspelt in the macro, or doesn’t exist in the Vault. Check the line ‘Set doc = alldocs(“123456.SLDDRW”)’

Note: It is not required to be logged into Workgroup PDM within SolidWorks, nor is it required to have “Workgroup PDM” turned on in Tools -> Add-Ins. It is required to have “Workgroup PDM” visible in Tools -> Add-Ins as this indicates that the PDM libraries are installed on your computer.

Note: It is possible to run this Macro from within SolidWorks (Tools -> Macro -> Run) and also from the SolidWorks Task Scheduler with a custom task.

Note: This is the macro in its simplest form. It would be possible to show an input dialog to allow a user select and choose which file to save out.

Note: While this macro was developed with SolidWorks 2010, it is possible to use this macro with all versions of SolidWorks. It would be best to copy and paste the code into a new macro in this case.

Note: If you re-run the macro, it will overwrite and replace any existing file.

SolidWorks Workgroup PDM API Help (pdmworksapi.chm)

This help file contains all the api references which can be used in Macros. This file is essential if you want to make full use of the workgroup PDM in Macros. Getting this file was a little difficult. SolidWorks’s help brought me to here, which wasn’t fully correct, but led me to this. A google before this led me to a 2008 version of this chm file, which fortunately had much more information and examples than the 2010 version. I’m going to provide a mirror of the files here, due to the large amount of broken links that occurs. Local Mirror of pdmworksapi-sw2008.chm and pdmworksapi-sw2010.chm. (You might have to go properties of the chm files after downloading and go “unblock”.) In the pdmworksapi-sw2008.chm, fortunately the Example contained therein had most of the macro in this post.

Stay tuned for more macros based on this simple example.

Macro , , , ,