wanacad1001 Posted June 23, 2020 Posted June 23, 2020 I need help to modify this lisp. The function of this lisp is to overwrite all the selected text string to XXX. But i want to modify this lisp so i can input the new string i want into all the selected text. The lisp code as below. (defun C:TXXX (/ ss n); = Text content to "XXX" (vl-load-com); if needed (prompt "\nTo change content of ALL selected Text/Mtext to \"XXX\",") (if (setq ss (ssget "_:L" '((0 . "*TEXT")))) (repeat (setq n (sslength ss)) (vla-put-TextString (vlax-ename->vla-object (ssname ss (setq n (1- n)))) "XXX") ); repeat ); if ); defun Thank you. Quote
Tharwat Posted June 23, 2020 Posted June 23, 2020 (edited) Welcome to CADTutor. Something like this? (defun c:Test (/ str e ss n) (if (and (setq str (getstring t "\nSpecify your text to overwrite selected texts : " ) ) (/= str "") (setq ss (ssget "_:L" '((0 . "*TEXT")))) ) (repeat (setq n (sslength ss)) (entmod (subst (cons 1 str) (assoc 1 (setq e (entget (ssname ss (setq n (1- n)))))) e ) ) ) ) (princ) ) Edited June 23, 2020 by Tharwat 1 Quote
Steven P Posted June 23, 2020 Posted June 23, 2020 Someone good will be along in a minute, but I would maybe make a new function along the lines of: (defun c:TXXXnew (/ newtext) (setq newtext (getstring)) (c:TXXX newtext) ) then changes in your C:TXXX to... (defun c:TXXX (/ ss n); to (defun c:TXXX (newtext / ss n) and (vla-put-TextString (vlax-ename->vla-object (ssname ss (setq n (1- n)))) "XXX") to (vla-put-TextString (vlax-ename->vla-object (ssname ss (setq n (1- n)))) newtext) tidied up to give: (defun c:TXXXnew (/ newtext) (setq newtext (getstring "Enter New Text")) (Tnew newtext) ) (defun Tnew (newtext / ss n); (vl-load-com); if needed (prompt (strcat "\nTo change content of ALL selected Text/Mtext to \""newtext"\",")) (if (setq ss (ssget "_:L" '((0 . "*TEXT")))) (repeat (setq n (sslength ss)) (vla-put-TextString (vlax-ename->vla-object (ssname ss (setq n (1- n)))) newtext) ); repeat ); if ); defun Quote
Steven P Posted June 23, 2020 Posted June 23, 2020 .. someone good came along as I was typing my answer.... Quote
Tharwat Posted June 23, 2020 Posted June 23, 2020 @Steven P Good stuff, and please note is that you can give the user the ability to type a string with spaces once you add the symbol 't' after the getstring function and furthermore, its really a good way of coding to have a check up in prior of the iteration process to avoid any error that may occur and here I am referring to the part if the user hits enter instead of typing the desired string ( text ). Happy coding. Quote
Steven P Posted June 23, 2020 Posted June 23, 2020 Thanks Tharwat, I didn't know that about the 't' - that is handy to know You are of course right also about checking to avoid errors - I'll change my idea around a bit for myself tomorrow. Quote
wanacad1001 Posted June 24, 2020 Author Posted June 24, 2020 The modified lisp is greatly work. Thanks everyone for the help i really appreciate it. 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.