X11start Posted August 23, 2022 Share Posted August 23, 2022 I would like to make a lisp that orders me the selected objects, in various ways: I'll give an example with numbers, but they could be polylines or any other object. 1 2 3 4 5 6 7 8 9 I would like to be able to select them with "Windows" and give them e.g. the Left-Right and top-down mode (as you read a text): 1 2 3 4 5 6 7 8 9 but also other ways e.g. from bottom to top and from right to left: 9 6 3 8 5 2 7 4 1 or from top to bottom and from left to right: 1 4 7 2 5 8 3 6 9 I Attached the lisp that I did and that runs only from left to right and from top to bottom... but I think you can find solutions faster than mine! My lisp is not complete: LISTA1 output contains the coordinates of the element + the selection set... a I just have to do SSADD to complete the command and create selection set final. SelSort.lsp ORDINE.lsp 1 Quote Link to comment Share on other sites More sharing options...
tombu Posted August 23, 2022 Share Posted August 23, 2022 On occasion when I've needed to select objects in a particular order I'll use the fence option. Not as quick as what you're looking for but faster than picking each one individually. Quote Link to comment Share on other sites More sharing options...
Steven P Posted August 23, 2022 Share Posted August 23, 2022 If the output is a list, you can go from 1 2 3 4 5 6 7 8 9 using " (reverse " which should give 9 8 7 6 5 4 3 2 1 Quote Link to comment Share on other sites More sharing options...
mhupp Posted August 23, 2022 Share Posted August 23, 2022 (edited) Build a selection set with ssget use a point of some type that all entity's have. (usually #10) build a list with the entity name and point. process the list using the point after sorting process entity's (if (setq SS (ssget "_:L")) ;#1 (progn (setq tlst (mapcar '(lambda (x) (list (cdr (assoc 10 (entget x))) x)) (vl-remove-if 'listp (mapcar 'cadr (ssnamex SS))))) ;#2 & 3 (setq tlst (mapcar 'cadr ;after sort strip point and only leave entity name (vl-sort tlst ;#4 '(lambda (a b) (if (equal (cadr (car a)) (cadr (car b)) 1e-6) ;if y are equal (< (caar a) (caar b)) ;true sort left most first (> (cadr (car a)) (cadr (car b))) ;false sort highest first ) ) ) ) ) ) ) (foreach ent tlst This method has some handy caps. Entity's need to be in a grid and basically a straight line. example. if #2 is higher then 1 it will be first in the list. Edited August 23, 2022 by mhupp 1 Quote Link to comment Share on other sites More sharing options...
BIGAL Posted August 24, 2022 Share Posted August 24, 2022 Have a look here http://www.theswamp.org/index.php?board=77.0 this page has numerous list manipulation examples. It would be a good location to ask for the 4 combinations that are possible for a matrix style sort XY points. The authors are very good at mapcar style answers so real short code. Quote Link to comment Share on other sites More sharing options...
X11start Posted August 24, 2022 Author Share Posted August 24, 2022 Thank you all for your help, especially to MHUPP: your lisp is definitely more effective than mine! Now on this basis, I will try to make sure that you can get the other 3 types of sorting (to the remaining 4 I follow the advice of STEVEN P... I use REVERSE!) Quote Link to comment Share on other sites More sharing options...
mhupp Posted August 24, 2022 Share Posted August 24, 2022 2 hours ago, X11start said: Thank you all for your help, especially to MHUPP: your lisp is definitely more effective than mine! Now on this basis, I will try to make sure that you can get the other 3 types of sorting (to the remaining 4 I follow the advice of STEVEN P... I use REVERSE!) or you can just switch how it sorts. 123 456 789 if statment for y sorts by row if statment for x sorts by column switch the > < signs to get the order you want ;sorts 321654987 (if (equal (cadr (car a)) (cadr (car b)) 2) ;if y are equal within 2 (> (caar a) (caar b)) (< (cadr (car a)) (cadr (car b))) ) ;sorts 963852741 (if (equal (caar a) (caar b) 2) ;if x are equal within 2 (< (cadr (car a)) (cadr (car b))) (> (caar a) (caar b)) ) ;sorts 147258369 (if (equal (caar a) (caar b) 2) (> (cadr (car a)) (cadr (car b))) (< (caar a) (caar b)) ) 1 Quote Link to comment Share on other sites More sharing options...
X11start Posted August 24, 2022 Author Share Posted August 24, 2022 (edited) ; ; (load "Selsort") ; (selsort 2) ; ... select object ... ; ; Verify: ; command -> Delete ; (nth 0 tlst) -> delete text "1" ; ; command -> Delete ; (nth 1 tlst) -> delete text "4" ; ; ... ; command -> Delete ; (nth 8 tlst) -> delete text "9" ; ; If TIPO > 4 TLST is reverse. ; ; ; 1 2 3 ; 4 5 6 ; 7 8 9 (defun SelSort (tipo / flag) (setq SS (ssget)) (setq tlst ; Crea una lista contenente le coord. x e y + il set di selezione (mapcar '(lambda (x) (list (cdr (assoc 10 (entget x))) x)) (vl-remove-if 'listp (mapcar 'cadr (ssnamex SS))) ) ) ;#2 & 3 ; (if (> tipo 4) ; se Tipo > 4 lo riporta ai primi 4 ma mette un Flag (setq tipo (- tipo 4) flag T) ) ; (if (= tipo 1) ; Sx-Dx & Up-Down -> 1-2-3-4-5-6-7-8-9 (setq tlst (mapcar 'cadr ;dopo aver ordinato il punto della striscia e lasciare solo il nome dell'entita' (vl-sort tlst ;#4 '(lambda (a b) (if (equal (cadr (car a)) (cadr (car b)) 1e-6) ;se y sono uguali (< (caar a) (caar b)) ;Se true: ordina prima a sinistra (> (cadr (car a)) (cadr (car b))) ;Se false: ordina prima il piu' alto ) ) ) ) ) ) ; (if (= tipo 2) ; Up-Down & Sx-Dx -> 1-4-7-2-5-8-3-6-9 (setq tlst (mapcar 'cadr ;dopo aver ordinato il punto della striscia e lasciare solo il nome dell'entita' (vl-sort tlst ;#4 '(lambda (a b) (if (equal (car (car a)) (car (car b)) 1e-6) ;se x sono uguali (> (cadr (car a)) (cadr (car b))) ;Se true: ordina prima il piu' alto (< (caar a) (caar b)) ;Se false: ordina prima a sinistra ) ) ) ) ) ) ; (if (= tipo 3) ; Dx-Sx & Up-Down -> 3-2-1-6-5-4-9-8-7 (setq tlst (mapcar 'cadr ;dopo aver ordinato il punto della striscia e lasciare solo il nome dell'entita' (vl-sort tlst ;#4 '(lambda (a b) (if (equal (cadr (car a)) (cadr (car b)) 1e-6) ;se y sono uguali (> (caar a) (caar b)) ;Se true: ordina prima a Destra (> (cadr (car a)) (cadr (car b))) ;Se false: ordina prima il piu' alto ) ) ) ) ) ) ; (if (= tipo 4) ; Up-Down & Sx-Dx -> 3-6-9-2-5-8-1-4-7 (setq tlst (mapcar 'cadr ;dopo aver ordinato il punto della striscia e lasciare solo il nome dell'entita' (vl-sort tlst ;#4 '(lambda (a b) (if (equal (car (car a)) (car (car b)) 1e-6) ;se x sono uguali (> (cadr (car a)) (cadr (car b))) ;Se true: ordina prima il piu' alto (> (caar a) (caar b)) ;Se false: ordina prima a Destra ) ) ) ) ) ) ; (if flag ; se Flag -> True Inverte la lista (setq tlst (reverse tlst)) ) ; ) I expanded the code of MHUPP... this is the result! thank you very much! Edited August 24, 2022 by X11start 2 Quote Link to comment Share on other sites More sharing options...
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.