+ Reply to Thread
Results 1 to 3 of 3

Building up a nested dictionary

  1. #1
    Registered User
    Join Date
    12-14-2018
    Location
    USA
    MS-Off Ver
    Office 365
    Posts
    26

    Building up a nested dictionary

    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

    Please Login or Register  to view this content.
    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.

  2. #2
    Forum Expert
    Join Date
    10-11-2021
    Location
    Netherlands
    MS-Off Ver
    365
    Posts
    1,404

    Re: Building up a nested dictionary

    There should be some kind of table in Excel from which you can load into VBA.
    First thing that comes in mind is a tree view. You can load that object with its CLSID.
    Last edited by JEC.; 09-12-2023 at 04:22 AM.

  3. #3
    Registered User
    Join Date
    12-14-2018
    Location
    USA
    MS-Off Ver
    Office 365
    Posts
    26

    Re: Building up a nested dictionary

    I actually figured out how to accomplish this yesterday. Below is the code with some comments to explain the SolidWorks native function calls.

    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Compiling and accessing nested collection within a nested dictionary
    By jrevball in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-06-2020, 10:20 AM
  2. Help to adjust code for nested dictionary to array
    By max138 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-21-2017, 05:40 AM
  3. [SOLVED] Dictionary or Scripting.Dictionary. Binding Referencing Dim-ing. Sub routines and Function
    By Doc.AElstein in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 07-12-2016, 08:28 AM
  4. [SOLVED] Comparing Arrays: What are tradeoffs b/w using a Dictionary vs a nested For-Each loops?
    By joe31623 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-04-2016, 01:29 PM
  5. Dictionary - Using a dictionary of dictionaries to hold individual orders
    By wazimu13 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-09-2015, 08:32 PM
  6. Nested dictionary items, how do you access them?
    By treyr in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-15-2010, 12:23 PM
  7. Template for building personal dictionary of foreign words
    By slovakwannabe in forum Excel - New Users/Basics
    Replies: 2
    Last Post: 02-14-2006, 06:25 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1