Page 1 of 1

PDM Checkin with API

Posted: Tue Mar 26, 2024 4:21 am
by mp3-250
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

Code: Select all

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

Code: Select all

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

Re: PDM Checkin with API

Posted: Tue Mar 26, 2024 4:52 am
by gupta9665
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).

Re: PDM Checkin with API

Posted: Tue Mar 26, 2024 5:43 am
by mp3-250
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.

Re: PDM Checkin with API

Posted: Tue Mar 26, 2024 8:22 am
by AlexB
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

Code: Select all

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:

Code: Select all

file.UnlockFile 0, "Test comment", 64

Re: PDM Checkin with API

Posted: Tue Mar 26, 2024 8:27 am
by mp3-250
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?

Re: PDM Checkin with API

Posted: Tue Mar 26, 2024 8:41 am
by AlexB
mp3-250 wrote: Tue Mar 26, 2024 8:27 am 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.

Re: PDM Checkin with API

Posted: Tue Mar 26, 2024 9:25 am
by mp3-250
AlexB wrote: Tue Mar 26, 2024 8:41 am 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.

Re: PDM Checkin with API

Posted: Tue Mar 26, 2024 9:28 am
by AlexB
mp3-250 wrote: Tue Mar 26, 2024 9:25 am @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 tje last two, but it works perfectly and the comment is left in the file history after the check out.
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.