PDM Searching with API
PDM Searching with API
I have a generated list of part numbers as a source. I am trying to get the path name of each part in PDM. Currently the only way I have figured out is to iterate through each item in my list, search it, and get the path. This is very time consuming as running the search multiple times takes approximately 2-3 seconds each. My list is currently 75 to 80 numbers long and will be growing in the future.
I am looking for a way to search multiple filenames. In other words generate a search with OR operators to compile a search result containing the files and then iterate through each search result and get the path. I am able do this in the quick search and search cards... but need a method through API.
I am looking for a way to search multiple filenames. In other words generate a search with OR operators to compile a search result containing the files and then iterate through each search result and get the path. I am able do this in the quick search and search cards... but need a method through API.
It is something that will run everytime someone invokes it. After seeing someone else's code I realized why it wasn't working. I had used CreateSearch method instead of CreateSearch2. I had glossed over the instruction in the search syntax section of the API help.
Go to full postRe: PDM Searching with API
I'm assuming you have PDM Pro. Do you like C# or VB? You haven't mentioned what you have started with as far as code so This link gives an overview of some PADM API concepts.
https://help.solidworks.com/2019/Englis ... 8dc4969c3b
Since you're searching this link should lead you to examples, they are searching by state, but you just change the search term to be your number.
https://help.solidworks.com/2019/Englis ... de4c3a#Pg0
Does that help?
https://help.solidworks.com/2019/Englis ... 8dc4969c3b
Since you're searching this link should lead you to examples, they are searching by state, but you just change the search term to be your number.
https://help.solidworks.com/2019/Englis ... de4c3a#Pg0
Does that help?
Re: PDM Searching with API
I tried using OR operators in a string in the EDMSearch.Filename.
I tried using BeginOR/EndOR with setting the Filename property multiple times in between.
I tried using SetToken with Edmstok_Name argument and OR operators in the search term argument and using BeginOR/EndOR and call SetToken multiple times.
It seems I need to use BeginOR/EndOR and AddVariable2 but I haven't been able to figure out what the variable name argument needs to be to get it to look at the filenames.
edit: I use VB.
I tried using BeginOR/EndOR with setting the Filename property multiple times in between.
I tried using SetToken with Edmstok_Name argument and OR operators in the search term argument and using BeginOR/EndOR and call SetToken multiple times.
It seems I need to use BeginOR/EndOR and AddVariable2 but I haven't been able to figure out what the variable name argument needs to be to get it to look at the filenames.
edit: I use VB.
Re: PDM Searching with API
Sorry, my links were probably too elementary for you based on what you're saying.
Are you searching for file name or data card variable? I was assuming Part Number variable, but now you're saying Edmstok_Name. If you're just looking for files that match filename then I don't see why you need to mess around with the OR clause.
Here's what I'm thinking
Or am I missing some requirement? I'm still assuming you have a simple list of ~100 part numbers. Or is that list from a PDM search in the vault view and you want to set up that search in API now?
Are you searching for file name or data card variable? I was assuming Part Number variable, but now you're saying Edmstok_Name. If you're just looking for files that match filename then I don't see why you need to mess around with the OR clause.
Here's what I'm thinking
Code: Select all
- get your list of part numbers (file names) into a KeyValue<string,string> partNums. maybe paste them into a listbox in a Form? Key can be part number, value empty.
- create a search
- foreach(pn in partNumss)
{
- myPNsearch.SetToken ( Edmstok_Name, pn.key )
_ while (searchresult != null)
{
- do some logic to verify results if you want the set pn.value = path you found
}
- myPNsearch.clear
}
Re: PDM Searching with API
My list is a CSV report run from our ERP. I was always able to find each file when I searched similar to how you laid out. What I am trying to avoid is running the search for each item in the list. The individual search for each item is causing my code to take over 5 minutes to run with just 80-100 items. My number of items will be growing and will just cause the load time to increase. If I could generate a search result list using OR operators I could drastically reduce the time needed to get past that step of my process.
You are correct in that I am trying to replicate a PDM search and generate a search result list containing the files for each item of my list.
You are correct in that I am trying to replicate a PDM search and generate a search result list containing the files for each item of my list.
Re: PDM Searching with API
I see.
Help page mentions there's overhead in creating the IEdmSearch5 object, did you create and dispose the search each iteration? Maybe that was causing it to be slow?
Help page mentions there's overhead in creating the IEdmSearch5 object, did you create and dispose the search each iteration? Maybe that was causing it to be slow?
Re: PDM Searching with API
One way that you may be able to get around this is to do the following:
1. Perform a search of the vault with filename "%.sld%" specified.
2. Iterate through each of the results adding them to a dictionary where the key is the filename and the value is the path.
3. For each of the files in your CSV, get the value for the from your dictionary instead of searching the vault for each item
Depending on your vault size, this initial search may be "expensive" however I believe the overall time searching for several files in your vault will eventually save you time.
Disclaimer: I haven't actually tested this method but something similar has worked for me in the past
1. Perform a search of the vault with filename "%.sld%" specified.
2. Iterate through each of the results adding them to a dictionary where the key is the filename and the value is the path.
3. For each of the files in your CSV, get the value for the from your dictionary instead of searching the vault for each item
Depending on your vault size, this initial search may be "expensive" however I believe the overall time searching for several files in your vault will eventually save you time.
Disclaimer: I haven't actually tested this method but something similar has worked for me in the past
Re: PDM Searching with API
I misspoke earlier when I said my list was 80-100 items. It is actually ~240 items.
I tried creating the search object once and doing a clear search after each item like you suggested. This definitely has helped. The load time is down to ~2:15. I would like to be able to get it down further. I would like to see how long it takes if I could get the multiple filename search to work. I think that would be the key to getting a decent load time.
I tried creating the search object once and doing a clear search after each item like you suggested. This definitely has helped. The load time is down to ~2:15. I would like to be able to get it down further. I would like to see how long it takes if I could get the multiple filename search to work. I think that would be the key to getting a decent load time.
Re: PDM Searching with API
80, 10, 200, shouldn't matter that much. Is this a once a day report type thing or something that users are triggering regularly? If once a day then I'd say a few minutes is fine. If it's something users are doing regularly and you expect that number to grow, I'd consider querying the Database directly. How comfortable are you with SQL in VB?MMartens wrote: ↑Wed Apr 28, 2021 1:30 pm I misspoke earlier when I said my list was 80-100 items. It is actually ~240 items.
I tried creating the search object once and doing a clear search after each item like you suggested. This definitely has helped. The load time is down to ~2:15. I would like to be able to get it down further. I would like to see how long it takes if I could get the multiple filename search to work. I think that would be the key to getting a decent load time.
Edit: another thought, you probably already know this, but the API search is almost no different then the GUI search. So the more terms that it's searching the longer it's going to take. I assume you're not searching all versions, and you've set it to only search files, not folders
Re: PDM Searching with API
It is something that will run everytime someone invokes it. After seeing someone else's code I realized why it wasn't working. I had used CreateSearch method instead of CreateSearch2. I had glossed over the instruction in the search syntax section of the API help.
Re: PDM Searching with API
Good to hear you got it working. That sounds like my kind of thing to do. Can you mark your solution post as best answer?MMartens wrote: ↑Wed Apr 28, 2021 3:27 pm It is something that will run everytime someone invokes it. After seeing someone else's code I realized why it wasn't working. I had used CreateSearch method instead of CreateSearch2. I had glossed over the instruction in the search syntax section of the API help.
Re: PDM Searching with API
Hey @MMartens. I was planning on attempting something very similar to what you've done. Was there any chance you'd be able to share what you've made with me to give me a bit of a head start?
Re: PDM Searching with API
Here is my sub I use...
The "names" variable can be a single name or several names separated by a space.
Code: Select all
Function getFileLocations(names As String) 'use PDM search to find files
Dim pdmVault As EdmLib.EdmVault5
Dim pdmBatchGetUtil As EdmLib.IEdmBatchGet
Dim pdmSearch As EdmLib.IEdmSearch9
Dim searchResult As EdmLib.IEdmSearchResult5
Set pdmVault = CreateObject("ConisioLib.EdmVault")
pdmVault.LoginAuto "EmtRoto", 0
Set pdmBatchGetUtil = pdmVault.CreateUtility(EdmUtil_BatchGet)
If Not pdmVault.IsLoggedIn Then
Err.Raise vbError, "User is not logged in to the vault"
Exit Function
End If
Dim pdmFolder As EdmLib.IEdmFolder12
Set pdmSearch = pdmVault.CreateSearch2
Set pdmFolder = pdmVault.GetFolderFromPath([i]YOUR ROOT FOLDER HERE[/i])
With pdmSearch
.SetToken Edmstok_AllVersions, 0
.StartFolderID = pdmFolder.ID
.Filename = names
.FindFiles = True
.FindFolders = False
.FindHistoricStates = False
End With
Set searchResult = pdmSearch.GetFirstResult
If searchResult Is Nothing Then
Exit Function
End If
Dim pdmFile As EdmLib.IEdmFile5
Dim pdmSelItems() As EdmLib.EdmSelItem
Dim i, n As Integer
i = 0
ReDim pdmSelItems(0 To 2)
'get the latest version of file
Do While Not searchResult Is Nothing
Set pdmFile = pdmVault.GetFileFromPath(searchResult.Path, pdmFolder)
If pdmFile.GetLocalVersionNo(pdmFolder) <> pdmFile.CurrentVersion Then
ReDim Preserve pdmSelItems(0 To i)
pdmSelItems(i).mlDocID = pdmFile.ID
pdmSelItems(i).mlProjID = pdmFolder.ID
i = i + 1
End If
Set searchResult = pdmSearch.GetNextResult
Loop
pdmBatchGetUtil.AddSelection pdmVault, pdmSelItems
pdmBatchGetUtil.CreateTree 0, EdmLib.EdmGetCmdFlags.Egcf_RefreshFileListing
pdmBatchGetUtil.GetFiles 0
End Function
Re: PDM Searching with API
Another solution is to get access to the SQL database itself. I just ran a query to cross reference between Dynamics AX 2012 items, and PDM files. 500k items came back with file locations based on 2 different search criteria's (Card variables, and file names) in about 27 seconds total. Searching for <500 files/items would be sub second.