12 Replies Latest reply on May 27, 2018 4:52 PM by Nilesh Patel

    PDM Get Latest not working

    Nilesh Patel

      Hi All,


      I have started learning PDM APIs and created a macro to get the latest version of the active document in SolidWorks, but I am not able to get the latest vesion. Here are the codes:


      Option Explicit
      Sub main()
          Dim swApp           As SldWorks.SldWorks
          Dim swModel         As ModelDoc2
          Dim swVault         As EdmVault5
          Dim swVault7        As IEdmVault7
          Dim swFile          As IEdmFile5
          Dim swFile12        As IEdmFile12
          Dim swFolder        As IEdmFolder5
          Dim swParFolder     As IEdmFolder5
          Dim swPos           As IEdmPos5
          Dim swSelFiles(0)   As EdmSelItem
          Dim swBatchGet      As IEdmBatchGet
          Set swVault = New EdmVault5
          Set swApp = Application.SldWorks
          Set swModel = swApp.ActiveDoc
          Debug.Print swModel.GetPathName
          If swVault.IsLoggedIn = False Then swVault.LoginAuto "Vault_Name", 0
          Set swFile = swVault.GetFileFromPath(swModel.GetPathName, swParFolder)
          Set swFile12 = swFile
          Debug.Print swFile.CurrentVersion
          Debug.Print swFile12.GetLocalVersionNo2(swModel.GetPathName, False)
          Set swPos = swFile.GetFirstFolderPosition
          Set swFolder = swFile.GetNextFolder(swPos)
          Debug.Print swFolder.LocalPath
          swSelFiles(0).mlDocID = swFile.ID
          swSelFiles(0).mlProjID = swFolder.ID
          Set swVault7 = swVault
          Set swBatchGet = swVault7.CreateUtility(EdmUtil_BatchGet)
          swBatchGet.AddSelection swVault, swSelFiles
          swBatchGet.CreateTree 0, EdmGetCmdFlags.Egcf_SkipExisting
          If swBatchGet.ShowDlg(0) = True Then swBatchGet.GetFiles 0, Nothing
          'swBatchGet.GetFiles 0, Nothing
      End Sub


      Below are the links of couple of forum I used as reference:

      EPDM 'Get Latest' code

      Solidworks EPDM 'Get latest' from VBA - Stack Overflow


      You can see the codes are quite similar but for some reason, I am not able to get the latest version of the document. I can get the local version (IEdmFile12::GetLocalVersionNo2) and the current version (IEdmFile5::CurrentVersion) of the document correctly but not able to get the latest version.


      I have already tried following:


      1. Passing the full document path instead of IModelDoc2::GetPathName.

      2. swSelFiles(0).mlDocID = 0 instead of swSelFiles(0).mlDocID = swFile.ID.

      3. swSelFiles(0).mlProjID = ("Folder Path").ID instead of swSelFiles(0).mlProjID = swFolder.ID &

      4. swBatchGet.CreateTree 0, EdmGetCmdFlags.Egcf_Nothing instead of swBatchGet.CreateTree 0, EdmGetCmdFlags.Egcf_SkipExisting


      But I am still not able to get the latest version of the active document in SolidWorks. What am I missing? I know there are plenty of PDM API gurus here, would someone be able to guide me?


      Thanks in advance.