PDM Checkin with API

I am trying to check in a file with a task VBA script, but instead of overwriting the latest version a new version is created

I replaced

file.UnlockFile 0, "Test comment"

in which 0 is the standar checkin with a 64, but it does not work.

’ EdmUnlock_FailOnRegenerationNeed 16 = Fail if the file needs to be regenerated in the CAD program
’ NOTE: Only files resaved in SOLIDWORKS 2009 or later can trigger this flag
’ EdmUnlock_ForceUnlock 256 = Unlock the file even if it is not modified
’ EdmUnlock_IgnoreCorruptFile 4 = Ignore files with file formats unrecognized by SOLIDWORKS PDM Professional; without this flag, SOLIDWORKS PDM Professional returns E_EDM_INVALID_FILE if it encounters a corrupt file or a file containing a newer format than SOLIDWORKS PDM Professional can handle
’ EdmUnlock_IgnoreReferences 128 = Silently unlock parent files without their references
’ EdmUnlock_IgnoreRefsNotLockedByCaller 32 = Ignore references not locked by caller
’ EdmUnlock_IgnoreRefsOutsideVault 8 = Ignore references to files outside the vault
’ EdmUnlock_KeepLocked 1 = Keep the file checked out after creating the new version in the archive
’ EdmUnlock_OverwriteLatestVersion 64 = Do not create a new version; overwrite the last version of the file with new changes
’ EdmUnlock_RemoveLocalCopy 2 = Remove the local copy of the file from the hard disk after the file has been checked in
’ EdmUnlock_Simple 0 = Check in the file using default behavior

Sample code below for the check in function

Private Function CheckInFile(strFileName As String) As String
On Error GoTo ErrHand

  Dim file As Object
  Dim oNull As Object
  Set file = Vault.GetFileFromPath(strFileName, oNull)

  If file Is Nothing Then

    'MsgBox "File not found."

    Exit Function

  End If

  file.UnlockFile 64, "Test comment"
 
  CheckInFile = "Successful"
  Exit Function

Not much expertise with PDM API but you will have to check out the existing file first (using lockfile method) and ad your file to PDM and release (unlockfile).

The checkout is not a problem, but i cannot overwrite the latest version when checking in. I do not understand why the argument is not working.

You’ll have to check and make sure you have permissions in PDM to do so. Can you verify this settings is checked for your PDM account via the admin tool?
image.png
Additionally, you are using the arguments in the incorrect order. You’ve passed 64 in as the window handle, not the flag argument.

Function

Sub UnlockFile( _
   ByVal lParentWnd As System.Integer, _
   ByVal bsComment As System.String, _
   Optional ByVal lEdmUnlockFlags As System.Integer, _
   Optional ByVal poIEdmRefCallback As System.Object _
)

Usage:

file.UnlockFile 0, "Test comment", 64

Unless the admin account missed that permission on the status I am testing that macro on, the problem could be …elsewhere?
If the permission is not a problem do you think setting 64 alone would be sufficient to trigger the latest version overwrite?

Yes, if used as the 3rd argument for the UnlockFile function instead of the first. See my edit to the end of my last post where I added the code example.

@alexb I took the argument as supplied by sw kb solution in the task script sample. when I looked at the api help I was a bit perplexed as there should be 4 arguments, while the sw devs were supplIng only the last two, but it works perfectly and the comment is left in the file history after the check out. it does not work for overwrite and you are probably right that more arguments should be supplied.

Yeah, the last 2 arguments are optional meaning that if you don’t supply them then they’re assumed to be the default values. I’m glad to hear it’s working now.