I've been using dictionaries in various projects but would like to know the correct way of creating a nested dictionary with multiple items where each item could be another dictionary? I'm writing a macro in a CAD program to access part information and save it to a collection. The coding to access part information is related to the CAD package I'm using but the building of the dictionary structure is related to VBA.
Scenario:
I have an assembly named "Parent Assembly" which contains two assemblies "Assem1" and "Assem2". "Assem1" contains parts "Part1" and "Part2" and "Assem2" contains parts "Part3" and "Part4". I've attached a graphic to show a visualization of this better. What I'm trying to do is add items to a dictionary whenever it comes across an assembly or a part. If it comes across a part it gets the information of that part and writes information to a class object and writes that class object to a result dictionary say ResultDict. If the code comes across an assembly, it should look to see if there are any parts and assemblies and apply the same recursive logic.
0.jpg
flow.PNG
psuedo code - I'm not sure how to effectively write my class object to the dictionary if the code needs to go deeper when it comes across nested assemblies
Even though this is an excel forum, I need to keep the solution solely within VBA without using excel functionality. So that means not writing a table of data for each level of TraverseComponents I am on, which is why I thought of using a dictionary of dictionaries built recursively.
Bookmarks