/// <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) { // //不一定要进行初始化对于 out 关键字 //可能还存在一定的问题 // GH_Structure <GH_Point> InputPtsTree;// = new GH_Structure<GH_Point>(); GH_Structure <GH_Point> OutputPts = new GH_Structure <GH_Point>(); double ThreadHold = default(double); string Sign = default(string); double Result = 0; GH_Path BasePath; if (!DA.GetDataTree <GH_Point>(0, out InputPtsTree)) { return; } if (!DA.GetData(1, ref ThreadHold)) { return; } if (!DA.GetData(2, ref Sign)) { return; } for (int K = 0; K < InputPtsTree.PathCount; K++) { //对每一个树枝进行遍历 // //We'll make a copy of the branch, so we can remove items from it // without modifying the original. We'll also remove all nulls from // //重点在这里 var BranchsPts = new List <GH_Point>(InputPtsTree.Branches[K]); //这里有点问题 BranchsPts.RemoveAll(point => point == null); BasePath = InputPtsTree.Paths[K]; int i = 0; if (BranchsPts.Count == 0) { return; } //对每一个Branch内的数据进行遍历处理 while (BranchsPts.Count > 0) { GH_Point i_Pt = BranchsPts[0]; List <GH_Point> NewBranch = new List <GH_Point> { i_Pt }; BranchsPts.RemoveAt(0); for (int j = 0; j < BranchsPts.Count; j++) { GH_Point j_Pt = BranchsPts[j]; switch (Sign.ToLower()) { case "x": Result = Math.Abs(i_Pt.Value.X - j_Pt.Value.X); break; case "y": Result = Math.Abs(i_Pt.Value.Y - j_Pt.Value.Y); break; case "z": Result = Math.Abs(i_Pt.Value.Z - j_Pt.Value.Z); break; case "d": Result = Math.Abs(i_Pt.Value.DistanceTo(j_Pt.Value)); break; default: Result = Math.Abs(i_Pt.Value.DistanceTo(j_Pt.Value)); break; } if (Result <= ThreadHold) { NewBranch.Add(BranchsPts[j]); BranchsPts.RemoveAt(j); j--; } } GH_Path NewPath = BasePath.AppendElement(i); i++; OutputPts.AppendRange(NewBranch, NewPath); } } // DA.SetDataTree(0, OutputPts); int BranchCount = InputPtsTree.Branches.Count; DA.SetDataTree(0, OutputPts); // DA.SetData(1, BranchCount); }