2013年3月15日 星期五

<分享>Group flatten List with different number

目標 : group flatten List with different number

檔案 : https://dl.dropbox.com/u/29860061/group%20flatten%20List%20with%20different%20number%28web%29.gh

比較 :


圖1 : 因為GH 內建所提供的data mapping 可以把flatten list 群組但是只限定每個branch中有固定的item,實在是不怎麼聰明。




圖2 : 所以我寫一個讓使用者可以依據想要的數量分別對使用者輸入flatten list,後進行不同數量的分組行為,大家可以看到處理後的數值在最右邊,分別依據使用者所輸入的5、4、5..等不同的群組內的數量作grouping

圖3 : 比較data mapping 與 C# grouping 的差別

注意 -----------> 
1.使用者輸入的數值請把它變成flatten list
2.輸入的分組數目總數請等於使用者所輸入flatten list的總數相等

example ->
分組數 3、3、6、2 -> 總數 3+3+6+2 = 14
flatten list的總數 -> 就是要數入14個數值






Main Code:


 DataTree<Point3d> myTree = new DataTree<Point3d>();

    //copy original objects
    List<Point3d> myLsPoints = new List<Point3d>();
    myLsPoints = xpoint;

    int tempInt;
    Print("count ={0}", yint.Count.ToString());
    int tempInt2;

    for(int i = 0;i < yint.Count;i++){

      tempInt = yint[i];

      GH_Path aa = new GH_Path(i);

      if(i == 0){

        tempIntA = 0;
      }else{
        tempInt2 = yint[i - 1];
        tempIntA += tempInt2;

      }
      Print("start index tempIntA ={0}", tempIntA);
      tempIntB = tempIntA + tempInt - 1;
      Print("end index tempIntB ={0}", tempIntB);

      List<Point3d> LsPoints = new List<Point3d>();
      for(int j = tempIntA;j <= tempIntB;j++){
        LsPoints.Add(myLsPoints[j]);
      }

      myTree.AddRange(LsPoints, aa);
    }

    A = myTree;



沒有留言:

張貼留言