I am trying to write a bit of code that will batch get library files when needed. I found and modified some code on this forum to do exactly this, but it doesn't seem to work for me. This is on EPDM 2012 SP3. Using Visual Studio 2010, C#. I am getting and invalid arguement exception on bg.AddSelection. Anyone care to take a look at it?
<p> EdmVault5 vault = new EdmVault5(); ;</p><p> </p><p> // Change "My Vault" to your vault name</p><p> vault.LoginAuto("My Vault", 0);</p><p> </p><p> // Change the number 2 in the following line to match the number of folders</p><p> EdmSelItem[] folders;</p><p> folders = new EdmSelItem[2];</p><p> </p><p> // The folders array index starts with 0.</p><p> // mlDocId = 0 tells EPDM you want all the files in the folder</p><p> folders[0].mlDocID = 0;</p><p> folders[0].mlProjID = vault.GetFolderFromPath("C:\\\\My Vault\\\\Library").ID;</p><p> folders[1].mlDocID = 0;</p><p> folders[1].mlProjID = vault.GetFolderFromPath("C:\\\\My Vault\\\\Misc").ID;</p><p></p><p> IEdmBatchGet bg;</p><p> bg = vault.CreateUtility(EdmUtility.EdmUtil_BatchGet);</p><p> bg.AddSelection(vault, folders);</p><p> bg.CreateTree(0, 8);</p><p> bg.GetFiles(0, null);</p><p></p>SolidworksSolidworks Pdm enterprise Pdm
I think all you need to do is convert vault.CreateUtility to the IEdmBatchGet type like so,
bg = vault.CreateUtility(EdmUtility.EdmUtil_BatchGet) as IEdmBatchGet;
That didn't work, same error on the AddSelection.
The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))
Have you checked that the folder paths are correct when you debug?
My array of EDMSelItem looks correct, both mlDocIDs are 0 and the mlProjIDs are 9 and 578, which I think would be correct.
You could try an alternate method:
<p>Array folders = Array.CreateInstance(typeof(EdmSelItem), 2);</p><p>EdmSelItem item = new EdmSelItem() { mlDocID = 0, mlProjID = vault.GetFolderFromPath("C:\\My Vault\\Library").ID };</p><p>folders.SetValue(item, 0);</p><p>item.mlProjID = vault.GetFolderFromPath("C:\\My Vault\\Misc").ID;</p><p>folders.SetValue(item, 1);</p>Still get the same error.
I wonder if permissions have something to do with it. Are you logged in as a user that has permission to those folders? Just a guess; the code looks fine.
I am logged in to the vault in question and have all permissions, and I can do a manual Get on those folders without issue.
Joe, did you manage to find a solution in the end? I'm running into the exact same problem now.
I know it's pretty easy to iterate through each file/folder and do an individual GetFileCopy() for each file, but I'd like to get this working if possible.
I don't know whether it's related, but I did find it strange that the AddSelection() method actually asks for an IEdmVault5 object, despite the fact that the API guide says it should be IEdmVault5. Additionally, IEdmVault7 is the earliest interface with a CreateUtility() method.
I did find something that works, when I get in to work today I'll dig up my source code and post it.
Here was my solution:
<p>EdmVault5 vault = new EdmVault5();</p><p></p><p>//Replace My_Vault with your vault name</p><p>vault.LoginAuto("My_Vault", 0);</p><p></p><p>//Set the 2 here equal to how many folders you want to get (not counting subfolders)</p><p>EdmSelItem[] fa = new EdmSelItem[2];</p><p>IEdmBatchGet bg = (IEdmBatchGet)vault.CreateUtility(EdmUtility.EdmUtil_BatchGet);</p><p> </p><p>//Create and array element for eachf older you want to get, replace folder locations with your folders</p><p>fa[0].mlDocID = 0;</p><p>fa[0].mlProjID = vault.GetFolderFromPath("C:\\My_Vault\\Misc").ID;</p><p>fa[1].mlDocID = 0;</p><p>fa[1].mlProjID = vault.GetFolderFromPath("C:\\My_Vault\\Library").ID;</p><p> </p><p>bg.AddSelection((EdmVault5)vault, (System.Array)fa);</p><p>bg.CreateTree(0, (int)EdmGetCmdFlags.Egcf_SkipExisting);</p><p><span style="font-size: 10pt;">bg.GetFiles(0, null);</span></p>Nope, still not working... Thanks for posting your code though.
Just wondering, which version of EPDM are you using?
Here is another solution,
Full implementation with Dialogue box for user etc is attached.
I know this has been marked as answered, but the answer has not seemed to work for everyone (myself included). What I suspected was that the issue was not in the code. I am using C# in Visual Studio and making the assembly COM-visible solved the problem for me (Solution Explorer -> [Project name] -> Properties -> Application tab -> Assembly Information... -> Make assembly COM-Visible).
Hopes this helps others.
Thanks, it was also my problem, the problem was not in the code.