fefaleite Posted September 15, 2023 Posted September 15, 2023 (edited) Hi, I found OneMtext.lsp and Text2MTextV2-0.lsp which are both very useful for my needs, but I wish that the contents could be set to sort by alphabetical order. Can anybody help me or point me in the direction of how to modify the lisp so I can have this result? Thank you OneMtext.lsp Text2MTextV2-0.lsp Edited September 15, 2023 by fefaleite Quote
exceed Posted September 18, 2023 Posted September 18, 2023 (edited) (defun 1MT (break / *error* done e objlst obj wid str strllen strlist) ; <- add these 2 variable name ....................................................... (setq str (vla-get-TextString obj)) ; Insert these lines below this line. (setq strlist (list str)) (foreach x (cdr objlst) (setq str (vla-get-TextString x)) (setq strlist (cons str strlist)) ); foreach (setq strlist (vl-sort strlist '<)) (foreach x (cdr objlst) (vla-delete x) ) (setq str (car strlist)) (setq strlist (cdr strlist)) (setq strllen (length strlist)) (repeat strllen (setq str (strcat str break (car strlist))) (setq strlist (cdr strlist)) ) ; up to this line (vla-put-TextString obj str) This is a modification of 1MT. Just add these lines in defun 1MT. ================================================================================== or You can do this by creating a new command by adding the original, ascending sort, and descending sort options. first, Add 0 one by one to the original 3 commands and add sort, reverse sort commands ; original (defun C:1MT0 (); all in one paragraph -- 1 space between, no Enter (1MT " " 0); Space for 'break' argument in 1MT (princ) ) (defun C:1MT1 (); new paragraph for each object's content -- 1 Enter (1MT "\\P" 0); Enter for 'break' argument in 1MT (princ) ) (defun C:1MT2 (); blank line & new paragraph for each object's content -- 2 Enters (1MT "\\P\\P" 0); 2 Enters for 'break' argument in 1MT (princ) ) ; sort (Ascending) (defun C:1MTS0 () (1MT " " 1) (princ)) (defun C:1MTS1 () (1MT "\\P" 1) (princ)) (defun C:1MTS2 () (1MT "\\P\\P" 1) (princ)) ; reverse sort (descending) (defun C:1MTRS0 () (1MT " " 2) (princ)) (defun C:1MTRS1 () (1MT "\\P" 2) (princ)) (defun C:1MTRS2 () (1MT "\\P\\P" 2) (princ)) then, add sortoption to argument (defun 1MT (break sortoption / *error* done e objlst obj wid str strllen strlist) then modify the above code by adding (cond) like this. (setq str (vla-get-TextString obj)) ; Insert these lines below this line. (cond ((= sortoption 0) ) ((or (= sortoption 1) (= sortoption 2)) (setq strlist (list str)) (foreach x (cdr objlst) (setq str (vla-get-TextString x)) (setq strlist (cons str strlist)) ); foreach (cond ((= sortoption 1) (setq strlist (vl-sort strlist '<)) ) ((= sortoption 2) (setq strlist (vl-sort strlist '>)) ) ) (foreach x (cdr objlst) (vla-delete x) ) (setq str (car strlist)) (setq strlist (cdr strlist)) (setq strllen (length strlist)) (repeat strllen (setq str (strcat str break (car strlist))) (setq strlist (cdr strlist)) ) ) (t ) ) ; up to this line (vla-put-TextString obj str) Edited September 18, 2023 by exceed 2 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.