List of Lists to Datatree - C# Nested Lists

Hi, here I am linking a Discussion in the old grasshopper forum about Datatrees, just because it took me a while to find it an I couldn’t find clear examples. An here is the function for converting from Nested Lists to Datatrees, that Andrew Heumann share in that discussion. Thanks

   DataTree<T> ListOfListsToTree<T>(List<List<T>> list){
       DataTree<T> tree = new DataTree<T>();
       int i = 0;
       foreach(List<T> innerList in list){
           tree.AddRange(innerList, new GH_Path(new int[]{0,i}));
           i++;
       }
   return tree;
   }

http://www.grasshopper3d.com/forum/topics/list-of-lists-to-datatree

7 Likes

You may find this recent thread interesting as well:

3 Likes