4 Replies Latest reply on Sep 4, 2018 11:24 AM by Robert Voogt

    PDM API - first pdm macro - clear cache command not working yet

    Robert Voogt

      HI all,


      I'm working on writing a macro to do the following:


      Get latest version of Folder A (in pdm)

      Process certain macro on folder A

      Empty local cache

      Get lateste version of Folder B, etc.

      Until it reaches the last given folder.


      (I have to empty the local cache every time between the folders because they are so large.)


      So I start with this:


      Dim swApp As Object
      Sub main()
      Dim vault As EdmVault5
      Set vault = New EdmVault5
      ' Change "My Vault" to your vault name
      vault.LoginAuto "Foodmate", 0
      ' Change the number 2 in the following line to match the number of folders
      Dim folders(1) As EdmSelItem
      ' The folders array index starts with 0.
      ' mlDocId = 0 tells EPDM you want all the files in the folder
      folders(0).mlDocID = 0
      folders(0).mlProjID = vault.GetFolderFromPath("C:\PDMWorks View\Foodmate\Sub samenstellingen\SA00000000-SA00009999").ID
      Dim bg As IEdmBatchGet
      Set bg = vault.CreateUtility(EdmUtil_BatchGet)
      bg.AddSelection vault, folders()
      bg.CreateTree 0, EdmGetCmdFlags.Egcf_SkipExisting
      bg.GetFiles 0, Nothing
      End Sub


      I run it in Solidworks, I have referenced PDMWorks Enterprise 2015 Type Library.


      It indeed sets all files local, it just takes a while. I hope that running a macro after this only starts when all files are truly local. Is there a way to have the macro wait until the complete folder is local?

        • Re: PDM API - first pdm macro - get latest version of folder
          Robert Voogt

          It seems to work so far, added a loop to get latest version of multiple given folders.


          How can I have it delete the local cache? I know that I have to work with IEdmClearLocalCache but is still difficult for me to understand.


          I added this to the code (to test clearing the cache):


          Dim ClearLocalCache As IEdmClearLocalCache3
          ClearLocalCache = vault.CreateUtility(EdmUtility.EdmUtil_ClearLocalCache)
          ClearLocalCache.IgnoreToolboxFiles = True
          ClearLocalCache.UseAutoClearCacheOption = True
          ClearLocalCache.CommitClear (Location(u))


          I get a Run-Time error 91 on the 2nd code row.

          I got a  'compile error, expected: =' on the last row when I left it empty ( ClearLocalCache.CommitClear () ) Therefor I added the location of the folder I want to clear the cache of.

            • Re: PDM API - first pdm macro - get latest version of folder
              Robert Voogt

              Got it to work:


              Dim ClearLocalCache As IEdmClearLocalCache3
              Dim FolderCC
              Dim vault           As EdmVault5
                      Set vault = New EdmVault5
                      vault.LoginAuto "Foodmate", 0
                      Set FolderCC = vault.GetFolderFromPath(FolderPath)
                      Set ClearLocalCache = vault.CreateUtility(19)
                      ClearLocalCache.IgnoreToolboxFiles = True
                      ClearLocalCache.UseAutoClearCacheOption = True
                      Call ClearLocalCache.AddFolder(FolderCC.ID, True)
                      Call ClearLocalCache.CommitClear(Nothing)



              This clears the local cache of a certain location (FolderPath string in my case)

            • Re: PDM API - first pdm macro - get latest version of folder
              Jerome De San Nicolás

              Hi there,

              I find this interesting so I made some search.

              It seems that you could wait for a function by WaitForSingleObject on a process ruining (like notepad, PDM search or PDM get i guess).

              I have manage to wait a process like this :



              Declare PtrSafe Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long
              Declare PtrSafe Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
              Public Const INFINITE = &HFFFF
              Function WaitForEnd(ByVal code As String) As Long
                  Dim ProcessHandle, processID As Long
                  ProcessHandle = OpenProcess(&H1F0000, 0, 14520)
                  WaitForEnd = WaitForSingleObject(ProcessHandle, INFINITE)
               End Function
              Sub testototototititi()
              Dim code As String
              WaitForEnd (code)
              MsgBox "END !!!"
              End Sub


              I cannot find a way to find the Process Id from running process.

              in the

              ProcessHandle = OpenProcess(&H1F0000, 0, 14520)


              the "14520" Correspond the the process ID (you can find it in the task manager) . But we need to find a way to telle the process name not ID