Jéferson Gustavo Posted September 16, 2020 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
dlanorh Posted September 16, 2020 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
Jéferson Gustavo Posted September 16, 2020 Author 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
BIGAL Posted September 17, 2020 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
Jéferson Gustavo Posted September 17, 2020 Author 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
ronjonp Posted January 8, 2021 Posted January 8, 2021 (edited) Please remove Edited January 8, 2021 by ronjonp Wrong thread Quote
Grrr Posted January 8, 2021 Posted January 8, 2021 Heres something for a generic grid point sort, also Lee covered that 'Ultimate Sorter' challenge of mine, so it seems alot shorter solution. Quote
Jéferson Gustavo Posted January 9, 2021 Author Posted January 9, 2021 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
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.