Grasshopper

algorithmic modeling for Rhino

Hi,

Is there a simpler method to convert nested collection to datatrees?

I have a method like this for 4 times nested arrays, similar to 3 times and 2 times nested ones.

Is there a shorter solution to convert nested arrays ?

For intance if I have 5 times nested array, do I need to another method, or there is a short quick version that combines all three methods below into 1?

public static DataTree<T> IEOfIEToTree<T>(IEnumerable<IEnumerable<T>> list, int iteration = 0) {
DataTree<T> tree = new DataTree<T>();
int i = 0;
foreach (IEnumerable<T> innerList in list) {
tree.AddRange(innerList, new GH_Path(new int[] { iteration, i }));
i++;
}
return tree;
}

public static DataTree<T> IE3<T>(IEnumerable<IEnumerable<IEnumerable<T>>> list, int iteration = 0) {
DataTree<T> tree = new DataTree<T>();
int i = 0;
foreach (IEnumerable<IEnumerable<T>> innerList in list) {
int j = 0;
foreach (IEnumerable<T> innerList2 in innerList) {
tree.AddRange(innerList2, new GH_Path(new int[] { iteration, i, j }));
j++;
}

i++;
}
return tree;
}

public static DataTree<T> IE4<T>(IEnumerable<IEnumerable<IEnumerable<IEnumerable<T>>>> list, int iteration = 0) {
DataTree<T> tree = new DataTree<T>();
int i = 0;
foreach (IEnumerable<IEnumerable<IEnumerable<T>>> innerList in list) {
int j = 0;
foreach (IEnumerable<IEnumerable<T>> innerList2 in innerList) {
int k = 0;
foreach (IEnumerable<T> innerList3 in innerList2) {

tree.AddRange(innerList3, new GH_Path(new int[] { iteration, i, j ,k}));
k++;
}

j++;
}

i++;
}
return tree;
}

Views: 403

Replies to This Discussion

Can you post sample data?

Hi,

I attached gh file.

Above one is from visual studio, that do not work by copying in gh.Sorry for that.

Attachments:

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service