When writing an add-in for SOLIDWORKS PDM, it is essential to consider compatibility across different versions of the software. Some API calls introduced in newer versions may not be available in older versions, potentially causing runtime errors for clients using older systems.
Scenario
Suppose your add-in uses an API feature introduced in SOLIDWORKS PDM 2022, but some clients are still using SOLIDWORKS PDM 2018. To ensure compatibility, you can programmatically check the PDM version installed on the client’s machine before calling the new API.
Solution: Use the GetVersion Method
The GetVersion method allows you to retrieve the major and minor version numbers of the installed SOLIDWORKS PDM Professional. Based on the version, your code can decide whether to execute the new API call or fall back to an alternative logic for older versions.
Implementation
Here is an example in Visual Basic:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
Sub CheckPDMVersionAndCallAPI() Dim vault As IEdmVault5 = New EdmVault5() Dim majorVersion As Integer = 0 Dim minorVersion As Integer = 0 ' Get the installed PDM version vault.GetVersion(majorVersion, minorVersion) If majorVersion >= 2022 Then ' Call the new API method CallNewAPIFeature() Else ' Fallback logic for older versions MsgBox("The new API is not supported on this version of SOLIDWORKS PDM. Please upgrade to 2022 or later.") End If End Sub Sub CallNewAPIFeature() ' Implement the new API feature here MsgBox("Calling the new API feature available in SOLIDWORKS PDM 2022.") End Sub |
This approach ensures your add-in remains robust and user-friendly, even in environments with mixed PDM versions.