Proper example that uses IEdmBatchGet to retrieve specific versions of PDM files (Not checkout) in VBA, C# or VB.NET?

The API help is pretty terse on this. The provided API example only covers checking files out in batch. I can’t seem to get it (the example) to work for retrieving specific file versions (Get). The only changes I made were :

Any direction or complete example on getting specific file versions using IEdmBatchGet would be highly appreciated.

1 Like

@AmenJlili
Here’s a bit of code that works for me in an add-in that I put together. Prior to this bit of code, I put together a Dictionary<IEdmReference10, int> object called RefFilesDictionary containing a reference to the file as the key and an integer of the file version I wish to get.

I had to manually iterate through the reference tree using IEdmFile5.GetReferenceTree(IEdmFolder5) and then refer to the file history with IEdmHistory.GetHistory(ref EdmHistoryItem[]) to determine which version met my criteria. If you want more specific info on either of these, let me know.

IEdmBatchGet batchGetter = (IEdmBatchGet)objVault.CreateUtility(EdmUtility.EdmUtil_BatchGet);

Callback?.ProgressBegin(EdmProgressType.Ept_Operation, RefFilesDictionary.Count);
int count = 1;
foreach (KeyValuePair<IEdmReference10, int> KvPair in RefFilesDictionary)
{
      Callback?.ProgressStep(EdmProgressType.Ept_Operation, $"Adding version {KvPair.Value} of {KvPair.Key.Name} to selections", count);
      batchGetter.AddSelectionEx((EdmVault5)objVault, KvPair.Key.FileID, KvPair.Key.FolderID, KvPair.Value);
      count++;
}
Callback?.ProgressEnd(EdmProgressType.Ept_FileTransfer);

if (RefFilesDictionary.Count > 0)
{
      batchGetter.CreateTree((int)thisWindow.Handle, (int)EdmGetCmdFlags.Egcf_Nothing);

      bool bRet = false;

      bRet = batchGetter.ShowDlg((int)thisWindow.Handle);

      if (bRet)
      {
            batchGetter.GetFiles((int)thisWindow.Handle, Callback);
            objVault.RefreshFolder(System.IO.Path.GetDirectoryName(pdmFile.GetLocalPath(ppoData[0].mlObjectID3)));
      }
}

That looks very promising. I will test this as soon as I get to my work desk.

I don’t want this line though:

bRet = batchGetter.ShowDlg((int)thisWindow.Handle);

Have you used without displaying any UI?

@AmenJlili
That line is completely optional as it will only bring up and show the dialog box for the user to adjust selections if they see fit. You can skip it and call batchGetter.GetFiles((int)thisWindow.Handle, Callback); to complete the action anyway.

Can’t get it to work.

Here’s my code if you want to try:

public static bool BatchGetLocalCopies(this IEdmVault5 Vault, IEdmFile5[] files, int[] versions, int Handle, IEdmGetOpCallback EdmGetOpCallback = null)
        {
            // create batch locker object 
            var batchLocker = (IEdmBatchGet)(Vault as IEdmVault8).CreateUtility(EdmUtility.EdmUtil_BatchGet) as IEdmBatchGet;
            // create the selection list 
       
            foreach (var file in files)
            {
                var version = versions[Array.IndexOf(files, file)];
                var v = Vault as EdmVault5;
                batchLocker.AddSelectionEx(v, file.ID, file.GetParentFolderID(), version);

            }
            //create tree 
            batchLocker.CreateTree(Handle, (int)EdmGetCmdFlags.Egcf_Nothing);
            // lock file 
            batchLocker.GetFiles(Handle, EdmGetOpCallback);

           
            return true;
        }

I’ve tried adapting your code to my add-in just to see if there’s something I’m missing. It looks like the following line isn’t in the API documentation that I am able to find.

IEdmFile5.GetParentFolderID()

If that’s something that you’re generating locally in your code, I’d start there to make sure you’re getting the correct folder ID when trying to add your reference to the selection list.

If you show the file dialog, it will display if you’ve been successful in your selections as a visual debugging tool even if you remove that from your code once verified.

Sorry. It’s an extension method to get the folder ID of the file’s parent folder.

You can replace that with

file.GetNextFolder(file.GetFolderFirstPosition()).ID

@BigCrazyAl : Any follow ups on this before we reach out to api support?

@AmenJlili I haven’t had time to sit down and look into this today with your code that you supplied. I’ll see if I’m able to get that going here shortly though.

1 Like

@AmenJlili
I’m getting an error with your folder ID method on some files. I had to modify my existing file with your logic and this is what I’m getting.
image

Are you handling errors with the folder ID to make sure your method isn’t exiting early?

Hmmm. No idea why you are getting that.

Few thoughts:

  • Are the files in the root folder? If not, forget this.
  • If you can replace that method with just the parent folder ID that you already have than you should be good.
  • Check if prefer 32 bits in the project properties is checked if you are running it from a console. if It is checked, check it off.

I double checked the settings just to be sure.

  • No files in the root folder
  • I was running my method side by side with yours to obtain the parent folder ID. The method you’re using seemed to have an issue when the parent folder ID was 0. I did find out that this issue was caused by weld fillet features for some reason and works fine when you manually set the parent folder ID to 0.
  • Prefer 32-bit is grayed out and cannot be selected.

My program runs with your approach in the same way that it runs with the way I initially set it up so I am not sure what the problem may be. Would you be willing to share your source code for further debugging?

So BatchGetLocalCopies work for you?

Yes, it’s working for me with my add in.

OK. Will have to test this again on my end…