CheckOut.swp (45,5 KB)
Hello everyone,
I have a VBA macro running inside SolidWorks that handles Check-Out and Check-In operations through the SOLIDWORKS PDM (EPDM) API.
The macro works correctly for both Check-Out and basic Check-In. I would now like to automatically add a comment during the Check-In phase, with the following fixed text (plus the current date and time generated at runtime):
“File insertion / update for CNC Machine Programs creation on dd/mm/yyyy at hh:mm:ss”
To do this, I tried casting IEdmFile5 to IEdmFile8 and calling UnlockFile2, which should accept a comment string as a fifth parameter.
Here is the relevant portion of the modified checkInFile sub:
Private Sub checkInFile(ByVal pdmVault, ByVal docType As Integer)
Dim swModel As SldWorks.ModelDoc2
Dim pdmFile As IEdmFile5
Dim pdmFile8 As IEdmFile8
Dim pdmFolder As IEdmFolder5
Dim ret As Integer
Dim lFlags As Long
Dim sComment As String
Set swModel = swApp.ActiveDoc
Set pdmFile = pdmVault.GetFileFromPath(swModel.GetPathName, pdmFolder)
If Not pdmFile.IsLocked Then
MsgBox "The file is not checked out.", vbInformation
Exit Sub
End If
sComment = "Inserimento / Aggiornamento file per creazione " & _
"Programmi Macchina utensile in data " & _
Format(Now(), "dd/mm/yyyy") & " ore " & Format(Now(), "hh:mm:ss")
If Me.chkMantienChkOut.Value = True Then
lFlags = EdmUnlock_OverwriteLatestVersion Or EdmUnlock_KeepLocked
Else
lFlags = EdmUnlock_OverwriteLatestVersion
End If
If swModel.ForceReleaseLocks Then
Set pdmFile8 = pdmFile
pdmFile8.UnlockFile2 pdmFolder.ID, handle, lFlags, sComment
End If
If docType = swDocDRAWING Then
ret = swApp.CloseAndReopen(swModel, swCloseReopenOption_DiscardChanges, swModel)
Else
ret = swModel.ReloadOrReplace(False, swModel.GetPathName, True)
End If
If Me.chkMantienChkOut.Value = True Then
MsgBox "Check-In completed. File kept checked out.", vbInformation
Else
MsgBox "Check-In completed.", vbInformation
End If
End Sub
My questions are:
- Is using
IEdmFile8/UnlockFile2the correct approach to pass a comment to the PDM vault on Check-In? - Do I need to add or update any Type Library reference in the VBA project for
IEdmFile8to be available? - Is there a simpler or more compatible alternative method?
Any help is greatly appreciated. Thank you!