Jump to content

Please help to modify this lisp... simple modification


Recommended Posts

Posted

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.

 

Posted (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 by Tharwat
  • Like 1
Posted

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 

 

Posted

.. someone good came along as I was typing my answer....

Posted

@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.

Posted

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.

Posted

The modified lisp is greatly work.

 

Thanks everyone for the help i really appreciate it.

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...