Nick24 Posted April 15, 2021 Posted April 15, 2021 (edited) Hi guys! Please help me with a small issue. For you it's really child's play. I made the following script and i want to turn it into a .lsp thru the "command" syntax (defun c:123()(command "zoom"......), but i have an error because the qoutation marks from the ssget function are misinterpreted when running the routine. ....... Z E select (setq ss (ssget "X" '((0 . "*TEXT")(62 . 7)))) TTT ....... Any help will be highly appreciated. Edited April 15, 2021 by Nick24 Quote
WHM Posted April 15, 2021 Posted April 15, 2021 If I understand you correctly, want to zoom to all your text with a color index of 7? If that is the case this should work for you: (defun c:abc123 (/ ss) (if (setq ss (ssget "X" '((0 . "*TEXT")(62 . 7)))) (progn (command "zoom") (mapcar 'command (acet-geom-ss-extents ss 1))))) 1 Quote
Nick24 Posted April 15, 2021 Author Posted April 15, 2021 (edited) 2 hours ago, WHM said: If I understand you correctly, want to zoom to all your text with a color index of 7? If that is the case this should work for you: (defun c:abc123 (/ ss) (if (setq ss (ssget "X" '((0 . "*TEXT")(62 . 7)))) (progn (command "zoom") (mapcar 'command (acet-geom-ss-extents ss 1))))) Thanks for the answer! Actually what the script does is zoom extents -> select all texts with colour 7 and then with a custom function (TTT) it exports selected texts to an Excel sheet. It worked great till now, but i want to run these commands all at once within a lisp routine. Edited April 15, 2021 by Nick24 Quote
mhupp Posted April 15, 2021 Posted April 15, 2021 (edited) ;;----------------------------------------------------------------------;; ;Zoom Extents and TTT command (defun C:ZE (/ SS) (command "_.Zoom" "E") (if (setq ss (ssget "X" '((0 . "*TEXT")(62 . 7)))) (C:TTT) ) ) To call other commands inside of a lisp you just have to wrap it with ( ) this will zoom extents and then make a selection set SS of all text and mtext that are color 7. if their is text that match that it will run TTT command. if TTT doesn't use SS for the selection set rename the variable to what ever TTT uses. or if TTT can handle all the selecting the text you just need. ;;----------------------------------------------------------------------;; ;Zoom Extents and TTT command (defun C:ZE (/) (command "_.Zoom" "E") (C:TTT) ) Edited April 15, 2021 by mhupp Quote
Nick24 Posted April 16, 2021 Author Posted April 16, 2021 (edited) 12 hours ago, mhupp said: ;;----------------------------------------------------------------------;; ;Zoom Extents and TTT command (defun C:ZE (/ SS) (command "_.Zoom" "E") (if (setq ss (ssget "X" '((0 . "*TEXT")(62 . 7)))) (C:TTT) ) ) To call other commands inside of a lisp you just have to wrap it with ( ) this will zoom extents and then make a selection set SS of all text and mtext that are color 7. if their is text that match that it will run TTT command. if TTT doesn't use SS for the selection set rename the variable to what ever TTT uses. or if TTT can handle all the selecting the text you just need. ;;----------------------------------------------------------------------;; ;Zoom Extents and TTT command (defun C:ZE (/) (command "_.Zoom" "E") (C:TTT) ) Thanks for the answer! Your routine is almost what i need, only thing is that it does not select the text i want. See below screenshot. It stops before selecting the text. I assume there's a problem with ssget function. I can attach TTT function if needed. Edited April 16, 2021 by Nick24 Quote
mhupp Posted April 16, 2021 Posted April 16, 2021 It would help. just to see how its handling the selection of text. Quote
Nick24 Posted April 16, 2021 Author Posted April 16, 2021 1 minute ago, mhupp said: It would help. just to see how its handling the selection of text. Please see below. In principal, i want it to zoom extents => select all texts with colour 7 => run TTT command. If you know other way to achieve this , other then what i pointed to, it's just as good. Thanks again! (defun LM:writecsv ( lst csv / des sep ) (if (setq des (open csv "w")) (progn (setq sep (cond ((vl-registry-read "HKEY_CURRENT_USER\\Control Panel\\International" "sList")) (","))) (foreach row lst (write-line (LM:lst->csv row sep) des)) (close des) t ) ) ) (defun LM:lst->csv ( lst sep ) (if (cdr lst) (strcat (LM:csv-addquotes (car lst) sep) sep (LM:lst->csv (cdr lst) sep)) (LM:csv-addquotes (car lst) sep) ) ) (defun LM:csv-addquotes ( str sep / pos ) (cond ( (wcmatch str (strcat "*[`" sep "\"]*")) (setq pos 0) (while (setq pos (vl-string-position 34 str pos)) (setq str (vl-string-subst "\"\"" "\"" str pos) pos (+ pos 2) ) ) (strcat "\"" str "\"") ) ( str ) ) ) (defun C:ttt(/ lst ss i el x fn) (setq lst (list) ss (ssget (list (cons 0 "TEXT"))) ) (repeat (setq i (sslength ss)) (setq x (ssname ss (setq i (1- i)))) (setq el (entget x)) (if (= (cdr (assoc 0 el)) "TEXT") (setq lst (append lst (list (list (cdr (assoc 1 el)))))) ) ) (setq fn (vl-filename-mktemp nil nil ".csv")) (if (and lst (LM:WriteCSV (reverse lst) fn)) (startapp "explorer" fn) ) ) Quote
mhupp Posted April 16, 2021 Posted April 16, 2021 Change the following in your lisp (setq lst (list) ss (ssget (list (cons 0 "TEXT"))) ) to (setq lst (list) ss (ssget "X" '((0 . "*TEXT")(62 . 7)))) ;this wont prompt to select objects b/c it selects everthing then filters down to text that are color 7 and then use the following ;;----------------------------------------------------------------------;; ;Zoom Extents and TTT command (defun C:ZET (/) (command "_.Zoom" "E") (C:TTT) ) I don't think this will work if the text you are trying to select are in blocks. Quote
Nick24 Posted April 16, 2021 Author Posted April 16, 2021 50 minutes ago, mhupp said: Change the following in your lisp (setq lst (list) ss (ssget (list (cons 0 "TEXT"))) ) to (setq lst (list) ss (ssget "X" '((0 . "*TEXT")(62 . 7)))) ;this wont prompt to select objects b/c it selects everthing then filters down to text that are color 7 and then use the following ;;----------------------------------------------------------------------;; ;Zoom Extents and TTT command (defun C:ZET (/) (command "_.Zoom" "E") (C:TTT) ) I don't think this will work if the text you are trying to select are in blocks. Unfortunately, the result is the same. It still stops at selecting texts and asks me to select what i want before proceeding with TTT command. PS: No texts are in blocks. Quote
Lee Mac Posted April 16, 2021 Posted April 16, 2021 Also answered here: https://stackoverflow.com/questions/67124190/multiple-commands-within-a-lisp-routine 1 Quote
Nick24 Posted April 17, 2021 Author Posted April 17, 2021 (edited) 19 hours ago, Lee Mac said: Also answered here: https://stackoverflow.com/questions/67124190/multiple-commands-within-a-lisp-routine Indeed, Lee Mac solved it Edited April 17, 2021 by Nick24 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.