Jéferson Gustavo 0 Posted September 16, 2020 Hello everyone, I need your help to create a function, which orders a list of points first by the first element (x), then by the second (y). I need this function to select objects from left to right, top to bottom. An example to be clearer: a list of points ((1 2 0) (1 1 0) (2 3 0) (2 1 0) (1 3 0) (2 2 0)) When applying the function returns: ((1 1 0) (1 2 0) (1 3 0) (2 1 0) (2 2 0) (2 3 0)). Thank you in advance! Note: forgive my English, I'm using a translator. Quote Share this post Link to post Share on other sites
dlanorh 290 Posted September 16, 2020 (edited) 9 hours ago, Jéferson Gustavo said: Hello everyone, I need your help to create a function, which orders a list of points first by the first element (x), then by the second (y). I need this function to select objects from left to right, top to bottom. An example to be clearer: a list of points ((1 2 0) (1 1 0) (2 3 0) (2 1 0) (1 3 0) (2 2 0)) When applying the function returns: ((1 1 0) (1 2 0) (1 3 0) (2 1 0) (2 2 0) (2 3 0)). Thank you in advance! Note: forgive my English, I'm using a translator. Try (setq lst (vl-sort lst '(lambda (x y) (if (= (car x) (car y)) (< (cadr x) (cadr y)) (< (car x) (car y)))))) where lst is the list you wish to sort This returns as per your post, however this is not left->right top->bottom but left->right bottom->top If you want top->bottom (setq s_lst (vl-sort lst '(lambda (x y) (if (= (car x) (car y)) (> (cadr x) (cadr y)) (< (car x) (car y)))))) should work Edited September 16, 2020 by dlanorh 1 Quote Share this post Link to post Share on other sites
Jéferson Gustavo 0 Posted September 16, 2020 4 hours ago, dlanorh said: Try (setq lst (vl-sort lst '(lambda (x y) (if (= (car x) (car y)) (< (cadr x) (cadr y)) (< (car x) (car y)))))) where lst is the list you wish to sort This returns as per your post, however this is not left->right top->bottom but left->right bottom->top If you want top->bottom (setq s_lst (vl-sort lst '(lambda (x y) (if (= (car x) (car y)) (> (cadr x) (cadr y)) (< (car x) (car y)))))) should work Tested it and it worked perfectly. Thank you very much! Quote Share this post Link to post Share on other sites
BIGAL 501 Posted September 17, 2020 (edited) You can go deeper in a sort than X Y eg block-name X Y Z att1 att2 Edited September 17, 2020 by BIGAL 1 Quote Share this post Link to post Share on other sites
Jéferson Gustavo 0 Posted September 17, 2020 11 hours ago, BIGAL said: You can go deeper in a sort than X Y eg block-name X Y Z att1 att2 good to know, thanks! Quote Share this post Link to post Share on other sites
ronjonp 224 Posted January 8 (edited) Please remove Edited January 8 by ronjonp Wrong thread Quote Share this post Link to post Share on other sites
Grrr 65 Posted January 8 Heres something for a generic grid point sort, also Lee covered that 'Ultimate Sorter' challenge of mine, so it seems alot shorter solution. Quote Share this post Link to post Share on other sites
Jéferson Gustavo 0 Posted January 9 13 hours ago, Grrr said: Heres something for a generic grid point sort, also Lee covered that 'Ultimate Sorter' challenge of mine, so it seems alot shorter solution. I found it more complex, I always take time to understand his codes, but I find it very clean and inspiring, nice code! Thanks! Quote Share this post Link to post Share on other sites