Rhino GH- Unflatten Component C# Snippet

You need the unflatten function of the unflatten component to write your own unflatten componenent in c#? I have something for you! You are welcome! But why? You may ask… Because it was late and i forgot, that there is a unflatten component in Grasshopper. Enjoy!

Get the example file on github!

The normal Grasshopper Unflatten component
My master piece! Does the same – but for sure slower!
    List<GH_Path> paths = new List<GH_Path>();

    // Iterates through every Branch and adds for every element in it the fitting adress to a pathlist.
    for (int p = 0; p < tree.Paths.Count; p++)
    {
      GH_Path pth = tree.Path(p);
      List<object> lst = tree.Branch(pth);

      for (int i = 0; i < lst.Count; i++)
        paths.Add(pth);
    }

    //The new datetree structure gets filled with the elements from the original list and the pathlist 
    DataTree<object> newTree = new DataTree<object>();
    
    for (int i = 0; i < list.Count; i++)
      newTree.Add(list[i], paths[i]);

    A = newTree;

If you have Questions – just write me! leonbrohman(at)gmx.de

Leave a comment