Please help me.
LINQ is not working properly
The C# code you posted works fine for me.
No way to know where your error is since you didn’t post a grasshopper file.
3. Attach minimal versions of all the relevant files
-Kevin
Thanks Kevin!
Sorry, my English isn’t so good.
test.3dm (30.3 KB)
test.gh (9.0 KB)
Here’s the file in question
please remember me
I believe @toolbox wants the numbers in your image that say 0, 5, 10, 15, 20 go 0, 1, 2, 3, 4.
This should do it.
List<Point3d> pt = Points.OrderBy(p => p.X).ThenBy(p => p.Y).ToList();
List<int> index_list = new List<int>();
for(int i = 0;i < Points.Count; i++) index_list.Add(i + 1);
P = pt;
I = index_list;
I simplified the provided GH a bit (put in a Point List to show native way for visualizing point indices without adding tags)
jesterKing__test.gh (7.7 KB)
Thanks Nathan ‘jesterKing’ Letwory
If you examine your points closely, you can see why they are not sorting in the order you expect.
I have rounded the values to 6 decimal places here (points are not modified, only their sorting criteria):
test_re.gh (19.7 KB)
-Kevin
Thank you Kevin!
That was very easy to understand!
Thank you so much.
It helped me a lot!!
It depends upon the “deviation” of your X/Y coords . That said Rounding IS NOT the answer for the general case: for that you’ll need another approach (a “special” GroupBy then an OrderBy).
See the challenge (set distort true) in the attached.
Points_InGrid_OrderByThenBy_V1.gh (116.8 KB)
Thanks Pfotiad0
So … as a challenge (not very simple mind) try to mastermind Methods that deal with the general case (i.e. a “distorted” rnd order grid, that is).
Tip: Cluster X,Y coords values Lists according some “gap” and get the related Intervals Lists (meaning that a given pt should get an index i if the X/Y value is included in some Interval at pos i).