Quantcast
Viewing all articles
Browse latest Browse all 8557

C# Splitting Data Tree into smaller chunks- incorrect output

@su.lwpac wrote:

Hi,
I am trying to split a data Tree into smaller chunks.
the Code seems to be working all fine, You can see here:

private void RunScript(DataTree<object> inputTree, ref object A)
  {
    var microTower = SplitBranchLists(inputTree);

    A = microTower;

  }

  // <Custom additional code> 

  public DataTree<object> SplitBranchLists(DataTree < object > inputDataTree)
  {
    DataTree<object> splitBranchLists = new DataTree<object>();
    int splitSize = 3;
    for(int i = 0; i < inputDataTree.BranchCount; i++)
    {
      var dataPath = inputDataTree.Paths[i];
      var dataList = inputDataTree.Branches[i];
      var remainder = dataList.Count % splitSize;
      var divisor = dataList.Count / splitSize;

      for (int n = 0; n < divisor; n++)
      {
        for ( int k = 0; k < dataList.Count - remainder; k += splitSize)
        {
          var tmpsum = 0;
          var startIndex = k + tmpsum;
          splitBranchLists.AddRange(dataList.GetRange(startIndex, splitSize), new GH_Path(dataPath.AppendElement(n)));
          Print(dataList.GetRange(startIndex, splitSize).Count.ToString());
          tmpsum += splitSize;

        }
      }
    }
    return splitBranchLists;
  }

But the Output is not what is expected.

Here is the Script also:
SplitDataTree.gh (9.5 KB)
What is missing, any Idea?

Posts: 2

Participants: 2

Read full topic


Viewing all articles
Browse latest Browse all 8557

Trending Articles