This topic contains the following information:
Writing a SolidWorks Workgroup PDM API application typically involves:
Instantiating a SolidWorks Workgroup PDM connection and logging in.
When you connect and log in to SolidWorks Workgroup PDM via the API, the SolidWorks Workgroup PDM API object model is implemented as a snapshot of what is in the vault at that time. If the state of the vault changes either through the user interface or the API (for example, by a check in, the creation of a new project, the addition of a note, and so on), you must call IPDMWConnection::Refresh to ensure that subsequent API calls return the most current data.
SolidWorks Workgroup PDM API contains several methods that change the state of the SolidWorks Workgroup PDM vault; however, most of the exposed object model contains read-only properties. Therefore, a typical SolidWorks Workgroup PDM application displays and analyzes vault data rather than updates it.
Getting and reading the various VB-compatible collections that represent:
documents in those projects, and
those projects' configurations, references, and other properties.
The SolidWorks Workgroup PDM API exposes VB-compatible collections for easy iteration of similar objects using the For Each...Next statement. For example, to iterate over the set of documents in a vault, you could use the following code fragment:
Dim connection As PDMWConnection
Dim allDocs As PDMWDocuments
Dim document As PDMWDocument
Set connection = CreateObject("PDMWorks.PDMWConnection")
connection.Login "pdmwadmin", "pdmwadmin", "vault_server_name"
Set allDocs = connection.documents
For Each document In allDocs
'Access each PDMWDocument here
Back to top
When appropriate, the SolidWorks Workgroup PDM API returns an error status code, for example, when performing IPDMWProperties::Update. Sometimes, directly returning a status code is not possible, for example, when retrieving a document via IPDMWConnection::GetSpecificDocument.
If an error status is returned, it is in the form of a SolidWorks Workgroup PDM error code (a 32-bit value). This code returns 0 for success and non-0 for error.
SolidWorks recommends that you use the intrinsic Visual Basic Err object to get rich error information. In this case, the Err.number field does not correspond directly to the SolidWorks Workgroup PDM error code, but mappings back to the error code are provided. The Err.Description field is filled with a descriptive text field indicating the error. In this way, better tracing of errors can be done through the Err object.
In Visual Basic 5.0, error handling can easily be accomplished with the On Error Resume Next statement. For example:
On Error Resume Next
Set conn = CreateObject(PDMWorks.PDMWConnection)
conn.Login user, incorrect password, vault
Err.number contains the error number
Err.description contains the appropriate error description
Back to top
SolidWorks Workgroup PDM is continually enhancing its APIs. In most instances, when an existing API is superseded by a new API, the new API has the same name as the existing API followed by a number. A higher number indicates a more recent API.
Superseded APIs are not supported. Help topics for superseded APIs are marked as obsolete.
SolidWorks recommends that you use the newest APIs in your code, and, whenever possible, update your existing code to use the newest APIs.
Back to top