Author Topic: Select Attribute to change text in the order it was selected  (Read 978 times)

0 Members and 1 Guest are viewing this topic.

EddieFromDc

  • Newt
  • Posts: 34
Hello,

I've been using this lisp routine for about 15 years now.
I apologize for not giving the creator credit cause I don't
who wrote this.

I was hoping that one of you experts can make it work for
mtext, an attribute in blocks and an attributes in dynamic
blocks too.

Thanks in advance.

;  TCC  Replace selected text lines with new text, line by line
(defun gtext ()
 (setq c 0 co 0 ss (ssget) ssl (sslength ss))(print)
)
;
(defun stng ()
 (if ss
  (progn
   (while (setq en (ssname ss c))
    (setq el (entget en))
    (setq ty (cdr (assoc 0 el)))
    (setq el1 (cdr (assoc 1 el)))
    (if (= ty "TEXT")
     (progn
      (if rl
       (progn
        (redraw en 3)
        (princ (strcat"      <" el1 "> "))
        (setq nt (getstring 1 "\n New text: "))
        (if (= nt "") (setq nt el1))
       )
      )
      (setq el (subst (cons 1 nt) (assoc 1 el) el))
      (entmod el)
      (setq co (1+ co))
      (if rl (setq nt ""))
     )
    )
    (setq c (1+ c))    ;else next entity
   )                   ;while
  )
 )
 (princ co) (princ " lines changed ")
 (if (null rl)
  (princ (strcat "to  " (chr 34) nt (chr 34)))
 )
)
;
;
(defun c:tcc (/ rl c co ss nt en ty el)
 (setq rl 1) (gtext) (stng) (princ)
)

BIGAL

  • Swamp Rat
  • Posts: 1411
  • 40 + years of using Autocad
Re: Select Attribute to change text in the order it was selected
« Reply #1 on: March 19, 2021, 11:21:50 PM »
You will need say a cond to seperate Text & Mtext, for me make a seperate defun for each variation and use a cond, so you have Text, mtext atts x2.

For mtext you would use VL much easier and look for the paragraph breaks \\p in the string and make say a list of each line, then just step through the list changing the text making a new list and last put the string back into the Mtext. Google Mtetxt to list shoudl be something out there.

Re attributes need to clarify what exactly do you want are you saying a attribute may be MTEXT  rather than just Text. Again 2 defun if INSERT &  ATT is TEXT, INSERT & ATT is MTEXT. Also which attribute ?

Maybe need a 3 choices before SSGET.


« Last Edit: March 19, 2021, 11:26:51 PM by BIGAL »
A man who never made a mistake never made anything