ryydman Posted July 19 Posted July 19 Hi all! I am new to AutoLISP programming. I wanted to try and create this program that would allow me to more easily edit text in AutoCAD. The program is working but I would like that the default input given to user wouldn't be highlighted or selected. That is a problem because if I then press enter it doesn't input anything. Also having the cursor on the right for easy editing would also be better. Is there a way to achieve this? My code: (defun c:TRE (/ ss i text textList filter) ;; Define the selection set filter to select only text objects (setq filter '((0 . "TEXT,MTEXT"))) ;; Select the text objects (setq ss (ssget filter)) (if ss (progn ;; Create list of entities from selection set (setq textList nil) (repeat (setq i (sslength ss)) (setq text (ssname ss (setq i (1- i)))) (setq textList (append textList (list text))) ) ;; Tolerance to y-coordinate sorting (setq tolerance 5.0) ;; Sorting text list from top to bottom left to right (setq textList (vl-sort textList (function (lambda (e1 e2) ;; check if on same y-coordinate (+-tolerance) then sort left to right otherwise sort top to bottom (if (< (abs (- (cadr (cdr (assoc 10 (entget e1)))) (cadr (cdr (assoc 10 (entget e2)))))) tolerance) (< (car (cdr (assoc 10 (entget e1)))) (car (cdr (assoc 10 (entget e2))))) (> (cadr (cdr (assoc 10 (entget e1)))) (cadr (cdr (assoc 10 (entget e2))))) ) ) ) ) ) ;; Going through each text and letting user modify (foreach text textList (entmod (subst (cons 1 (getstring T (strcat "Edit text: <" (cdr (assoc 1 (entget text))) "> -> "))) (assoc 1 (entget text)) (entget text))) (entupd text) ) (princ "\nText objects edited successfully.") ) ; end of progn (princ "\nNo objects found in the specified area.") ) ; end of if ss (princ) ) ; end of program All help is appreciated! Best regards Quote
pkenewell Posted July 19 Posted July 19 Give this a try: (defun c:TRE (/ ss i text textList ntxt otxt filter) ;; Define the selection set filter to select only text objects (setq filter '((0 . "TEXT,MTEXT"))) ;; Select the text objects (setq ss (ssget filter)) (if ss (progn ;; Create list of entities from selection set (setq textList nil) (repeat (setq i (sslength ss)) (setq text (ssname ss (setq i (1- i)))) (setq textList (append textList (list text))) ) ;; Tolerance to y-coordinate sorting (setq tolerance 5.0) ;; Sorting text list from top to bottom left to right (setq textList (vl-sort textList (function (lambda (e1 e2) ;; check if on same y-coordinate (+-tolerance) then sort left to right otherwise sort top to bottom (if (< (abs (- (cadr (cdr (assoc 10 (entget e1)))) (cadr (cdr (assoc 10 (entget e2)))))) tolerance) (< (car (cdr (assoc 10 (entget e1)))) (car (cdr (assoc 10 (entget e2))))) (> (cadr (cdr (assoc 10 (entget e1)))) (cadr (cdr (assoc 10 (entget e2))))) ) ) ) ) ) ;; Going through each text and letting user modify (foreach text textList (setq otxt (cdr (assoc 1 (entget text))) ntxt (getstring T (strcat "Edit text: <" otxt "> -> ")) ) (if (= ntxt "")(setq ntxt otxt)) (entmod (subst (cons 1 ntxt) (assoc 1 (entget text)) (entget text))) (entupd text) ) (princ "\nText objects edited successfully.") ) ; end of progn (princ "\nNo objects found in the specified area.") ) ; end of if ss (princ) ) ; end of program 1 Quote
ryydman Posted July 19 Author Posted July 19 4 minutes ago, pkenewell said: Give this a try: (defun c:TRE (/ ss i text textList ntxt otxt filter) ;; Define the selection set filter to select only text objects (setq filter '((0 . "TEXT,MTEXT"))) ;; Select the text objects (setq ss (ssget filter)) (if ss (progn ;; Create list of entities from selection set (setq textList nil) (repeat (setq i (sslength ss)) (setq text (ssname ss (setq i (1- i)))) (setq textList (append textList (list text))) ) ;; Tolerance to y-coordinate sorting (setq tolerance 5.0) ;; Sorting text list from top to bottom left to right (setq textList (vl-sort textList (function (lambda (e1 e2) ;; check if on same y-coordinate (+-tolerance) then sort left to right otherwise sort top to bottom (if (< (abs (- (cadr (cdr (assoc 10 (entget e1)))) (cadr (cdr (assoc 10 (entget e2)))))) tolerance) (< (car (cdr (assoc 10 (entget e1)))) (car (cdr (assoc 10 (entget e2))))) (> (cadr (cdr (assoc 10 (entget e1)))) (cadr (cdr (assoc 10 (entget e2))))) ) ) ) ) ) ;; Going through each text and letting user modify (foreach text textList (setq otxt (cdr (assoc 1 (entget text))) ntxt (getstring T (strcat "Edit text: <" otxt "> -> ")) ) (if (= ntxt "")(setq ntxt otxt)) (entmod (subst (cons 1 ntxt) (assoc 1 (entget text)) (entget text))) (entupd text) ) (princ "\nText objects edited successfully.") ) ; end of progn (princ "\nNo objects found in the specified area.") ) ; end of if ss (princ) ) ; end of program Thank you! This solves the issue of having no text input but I'm still wondering if there's some way to have the cursor on the right automatically without having to move it there. I know it's a small thing but the whole point of this code was to make editing multiple text as easy as possible Anyways thanks a lot for helping! Quote
pkenewell Posted July 19 Posted July 19 34 minutes ago, ryydman said: Thank you! This solves the issue of having no text input but I'm still wondering if there's some way to have the cursor on the right automatically without having to move it there. I know it's a small thing but the whole point of this code was to make editing multiple text as easy as possible Anyways thanks a lot for helping! I'm not sure what you mean by "way to have the cursor on the right automatically". If you mean move the cursor to where the text is, then the answer is no. Alternatively, you could zoom in to where the text is perhaps? 1 Quote
BIGAL Posted July 20 Posted July 20 Are you saying you want to add a Suffix to each text ? Like this "Pt" = "Pt 123" . Every Pt is numbered. Please explain more the desired result. 1 Quote
ryydman Posted July 20 Author Posted July 20 18 hours ago, pkenewell said: I'm not sure what you mean by "way to have the cursor on the right automatically". If you mean move the cursor to where the text is, then the answer is no. Alternatively, you could zoom in to where the text is perhaps? 7 hours ago, BIGAL said: Are you saying you want to add a Suffix to each text ? Like this "Pt" = "Pt 123" . Every Pt is numbered. Please explain more the desired result. Sorry for my bad explanation I attached a gif that hopefully clears things up. There you can see when you get the default text it is automatically highlighted and you have to move the cursor to the right every time when usually what you want to change is on the right. So I understand I could create another program to work better with just adding the suffix but what I wanted this program to do was just generally make all text editing, when theres a lot of it, easier with no mouse movements required. Seems like there isn't a way to do that but this already helps nicely. Thanks again for the help! 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.