Esempio n. 1
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            List <Curve>            Crvs       = new List <Curve>();
            double                  ThreadHold = 0.1;
            string                  SortSign   = "x";
            GH_Structure <GH_Curve> OutputTree = new GH_Structure <GH_Curve>();

            if (!DA.GetDataList(0, Crvs))
            {
                return;
            }
            if (!DA.GetData(1, ref ThreadHold))
            {
                return;
            }
            if (!DA.GetData(2, ref SortSign))
            {
                return;
            }

            int SortIndex = SortSign.ToLower() == "x" ?
                            0 : SortSign.ToLower() == "y" ?
                            1 : SortSign.ToLower() == "z" ?
                            2 : 0;


            var GroupData = Crvs.GroupBy(Crv => { double Pt_Seg = Crv.PointAtNormalizedLength(0.5)[SortIndex]; return(Pt_Seg * (1 / ThreadHold)); }).ToList();

            for (int Index = 0; Index < GroupData.Count; Index++)
            {
                var TempGroup  = GroupData[Index];
                var TreeBranch = TempGroup.Select(Crv => new GH_Curve(Crv)).ToList();
                OutputTree.AppendRange(TreeBranch, new GH_Path(Index));
            }

            DA.SetDataTree(0, OutputTree);
        }