is there a way - built into the API of SolidWorks or the Document Manager - to find a Top Level Assembly from a list of assemblies in a folder?
With the Document Manager, you could traverse all assemblies until you find one that isn't used anywhere. In other words, the array returned by ISwDMDocument::WhereUsed will be empty. Note that the object parameter, pSrcOption, lets you specify where to perform the "Where Used" search. As long as you limit the search to the desired directory, you should get the correct result. (Sub-folders will get searched, by the way.)
SolidWorks API Tutorials
Thank You Keith
You're welcome. If you believe I answered your question correctly, you mind marking it as correct? I would appreciate it.
this seemed like it should work but...
WhereUsed seems to be returning contents of assemblies instead of where its used.
Below "AssyList" returns the contents of the assembly NOT where the assembly is used.
I'm running SolidWorks 2012 SP5.0
Dim swCf As SwDMClassFactory
Dim swDocMgr as SwDMApplication3
swDocMgr = swCf.GetApplication("my number goes here")
Dim swDoc as ISDMDocument15
Dim psrcopt As SwDMSearchOption
For Each Path as String in List_of_Assemblies
swDoc = swDocMgr.GetDocument(Path, SwDocTypeAssy, False, swDmDocOpenErr)
Dim AssyList as Array
psrcopt = swDocMgr.GetSearchOptionObject
AssyList = swDoc.WhereUsed(psrcopt)
No I was wrong.
The code above is correct in that it returns every instance of where the assembly is used.
but since "WhereUsed" does return an array I don't know how it will work.
Even though an assembly is "Top Level" it can be used for external referances.
I see. It sounds like you're saying that if a component is created in the context of an assembly, the parent is considered "used" by that component.
Using ISwDmSearchOptions::SearchFilters, it appears that you can limit what types of references you can search for. For example, see SwDmSearchExternalReference. Maybe this ignores in context references? At the very least, perhaps you could get the entire references list and then remove from that list the references returned using SwDmSearchInContextReference. Maybe that would contain only "Where is this a component" references.
psrcopt.SearchFilters = SwDmSearchFilters.SwDmSearchInContextReference
results in an empty array.
commenting out the ''' "psrcopt.SearchFilters = SwDmSearchFilters.SwDmSearchInContextReference"
results in an array of file names that are being "used" by the assembly.
so using the Search.Filters does something maybe I'm using wrong?
I would recommend emailing API support about the exact usage of these search options. Unfortunately I don't have enough experience with these search options to give you a definitive answer. I hope I haven't taken you down a rabbit hole already.
Retrieving data ...