GetFilesBySearchCriteria

GetFilesBySearchCriteria

cavallerin
Enthusiast Enthusiast
234 Views
8 Replies
Message 1 of 9

GetFilesBySearchCriteria

cavallerin
Enthusiast
Enthusiast
Dim mSearchParams As New System.Collections.Generic.Dictionary(Of String, String) 

mSearchParams.Add("File Name", "ENG0000024.iam") 
mSearchParams.Add("File Name", "ENG0000025.iam") 
mSearchParams.Add("File Name", "ENG0000079.iam") 
mSearchParams.Add("File Name", "ENG0000097.iam") 
mSearchParams.Add("File Name", "ENG0000100.iam") 

Dim mVaultFiles As List(Of String)
mVaultFiles = iLogicVault.GetFilesBySearchCriteria(mSearchParams, False, False) 

I'm testing this rule, but when I run it it returns me the error  

 

Errore alla riga 4 nella regola: GetLatestVersion_1, nel documento: Parte1

An item with the same key has already been added. Key: File Name

 

Can't understand why. The hint when you insert the function says:

'Build one to many name/value pairs of Property/Value as search criteria;
Dim mSearchParams As New System.Collections.Generic.Dictionary(Of String, String) 'add UDP.DisplayName, Value Pairs
mSearchParams.Add("Part Number", "00100*")		'applies to files from 001000 to 001009
'...add as many as required to enable a unique search result

'the list of downloaded files
Dim mVaultFiles As List(Of String)
0 Likes
Accepted solutions (2)
235 Views
8 Replies
Replies (8)
Message 2 of 9

WCrihfield
Mentor
Mentor
Accepted solution

Hi @cavallerin.  It looks like you are using the following uniquely iLogic method:

iLogicVaultClass.GetFileBySearchCriteria Method (Dictionary(String, String), Boolean, Boolean, Strin... 

It looks like there are a few variations of that method, which ask for different inputs.

 

I do not have Vault, and have never used that method before, but I am very familiar with Dictionaries.  When adding entries into a Dictionary, each entry is known as a KeyValuePair, and the first part of each entry is called the 'Key', and the second part of each entry is the 'Value'.  Each 'Key' in a Dictionary must be unique from all other 'Keys' in that Dictionary, but the Values can be different.  So, it does not like that all of your entries have the same 'Key' portion ("File Name").  So, the error is related to the Dictionary Type, not necessarily the iLogic method.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 9

cavallerin
Enthusiast
Enthusiast

Yep, you're right that's the common usage of a Disctionary.

Maybe it is the italian translation of the hint that led me to this misunderstanding.

As you may see from the screen shot the function just above the one highligthed says: "Ottieni file del Vault mediante ricerca". This is not clear because in italy we use "file" (without the letter s) as for singular and for plural.

Infact the highlighted function's name is: "Ottieni più file del Vault mediante ricerca" the word "più" it can be translated with more.

Then by an italian reader it seems that first function it is used only to look for one single file; while the second function it seems it can be used to look for more files.

 

In any case the hint "Cerca uno o più file e li scarica tutti" in italian it means that you are able to look for one to many files and download them all in a unique shot, but as you pointed the functionality, each Dictionary allows only unique keys in its data structured; so by a coding point of view it is correct, by a interface point of view the Italian translation leads to a misunderstanding (I.M.O.)

 

Regards

cavallerin_0-1749533576659.png

 

Message 4 of 9

mateusz_baczewski
Advocate
Advocate

Hi @cavallerin ,

 

You know, it seems to me that the GetFilesBySearchCriteria method works the same way as searching in Vault. I'm showing you an example where you add search criteria and get a large number of files that contain a given phrase. If you want to search for every file, in my opinion, you need to iteratively check each file and create a dictionary with search criteria for each file. But then, I think you also need to check if the list of files you’re asking about is a single-element list or if there are multiple elements in the list, because if there are, you still need to check which of these files is the one you are looking for.

 

In your case, you can’t do what you want because a dictionary can’t have two identical keys.

 

mateusz_baczewski_0-1749555459360.png

If you found it helpful, a "Like" would be much appreciated!
If this post solved your problem, please mark it as "Solution.".

Message 5 of 9

cavallerin
Enthusiast
Enthusiast

You're right. In the end, the code solution I have implemented creates and destroys the same rule inside the inventor file, and each time it searches for a specific file name from a given list of file names.

So, in each iteration, a new iLogic rule with a specific file name is created, the file is retrieved from the Vault, then the rule is deleted, and then the next iteration begins.

I know it's a "poor. man way" solution, but it is the only inexpensive way I found to complete my "prototype." Once the project is delivered, all this will be "better codified."

0 Likes
Message 6 of 9

g.georgiades
Advocate
Advocate

When searching vault, if you want to search for multiple values for the same property in one search, you have to separate the search terms with the word "or" and the search must be of type "contains".

 

It looks like the inventor vault GetFilesBySearchConditions is not configured to run this way. It is looking for exact matches and it cannot be configured.

This is likely intentional due to the way vault searches using "contains" - the results tend to pull in a lot of undesired results, though it can be changed in the vault server settings.

 

Your only options are to perform multiple, independent searches (which you have already figured out), or manually implement the search using the vault api so you have more control on the search settings.

 

Here is an example i found on the vault forum

https://forums.autodesk.com/t5/vault-customization-forum/vault-api-tool-check-if-file-is-in-vault/m-...

And one from the vault blog

https://justonesandzeros.typepad.com/blog/2012/09/finding-by-search-conditions.html

 

 

 Here is the search types that can be used. InventorVault only uses 3. It would need to allow 1 to allow for multiple searches using the same property.

ggeorgiades_0-1749576161468.png

 

@MjDeck Can inventor vault searches be expanded to allow some of the other SrchOper flags, or maybe make it clearer that current functionality only uses 3 ("Is Exactly")

0 Likes
Message 7 of 9

MjDeck
Autodesk
Autodesk
Accepted solution

Hi @g.georgiades - yes, it could be expanded to allow some of the other SrchOper flags. But @cavallerin wants to do this:

mSearchParams.Add("File Name", "ENG0000024.iam") 
mSearchParams.Add("File Name", "ENG0000025.iam")
' ...

That doesn't need a "contains" match. It needs to be able to search for several specified exact values of the same property.
We could support that by adding a new version of the GetFilesBySearchCriteria function to iLogic Vault. Instead of a Dictionary, the new function would take a list of key-value pairs. Then you could add entries for many filenames.


Mike Deck
Software Developer
Autodesk, Inc.

0 Likes
Message 8 of 9

g.georgiades
Advocate
Advocate

@MjDeck You are correct, but the downside to that is multiple vault server requests will have to be made. Depending on the number of items, it could have a large performance impact since vault searches are slow.

 

Searching using "contains" means this can be done using one server call. However, the downside is that the way vault searches using contains could lead to extra results that have to be filtered out later.

mSearchParams.Add("File Name", "ENG0000023.iam or ENG0000024.iam or ENG0000025.iam", 1) 'SrchOper=1 (Contains)

 

I think both ways are "right", but it should be clearly indicated what kind of performance is expected.

 

Another thing is the benefit of multi-key searching eg this type of search is not possible with the current implementation, and the proposed solution by you would treat these as separate searches instead of one.

mSearchParams.Add("File Name", "Project Part*.ipt", 1) 'SrchOper=1 (Contains)
mSearchParams.Add("Author", "user", 3) 'SrchOper=3 (Is Exactly)

 

0 Likes
Message 9 of 9

MjDeck
Autodesk
Autodesk

@g.georgiades , with my proposed change you could find all the files with a single call to Vault. The iLogicVaultClass.GetFilesBySearchCriteria function has an optional MatchAllCriteria argument. If you set that to False then the search will be done with each condition as an "Or" condition.

But if we're going to provide a new version of the function, it would be good idea to provide a way to set the SrchOper, as you're showing. We could also allow you to set the "And" or "Or" on each condition (the SearchRuleType in the Vault SDK).


Mike Deck
Software Developer
Autodesk, Inc.

0 Likes