LISP to trim the first character of multiple texts

LISP to trim the first character of multiple texts

Anonymous
Not applicable
1,333 Views
3 Replies
Message 1 of 4

LISP to trim the first character of multiple texts

Anonymous
Not applicable

I need a Lisp that can trim the first character of multiple texts.

Please help

thank you in advance.

0 Likes
1,334 Views
3 Replies
Replies (3)
Message 2 of 4

Kent1Cooper
Consultant
Consultant

If they're all Text/Mtext without any internal formatting  before the first "real" character, maybe something like this [in simplest terms, minimally tested]:

 

(defun C:T-1 (/ ss n tdata)
  (prompt "\nTo remove the first character from Text/Mtext,")
  (if (setq ss (ssget '((0 . "*TEXT"))))
    (repeat (setq n (sslength ss)); then
      (setq tdata (entget (ssname ss (setq n (1- n)))))
      (entmod
        (subst
          (cons 1 (substr (cdr (assoc 1 tdata)) 2)); drop first character
          (assoc 1 tdata)
          tdata
        )
      )
    )
  )
)

 

Kent Cooper, AIA
0 Likes
Message 3 of 4

lewyee1976
Explorer
Explorer

mod code to trim from last char!

 

(defun C:TRR (/ ss n tdata)
(prompt "\nTo remove the first character from Text/Mtext,")
(if (setq ss (ssget '((0 . "*TEXT"))))
(repeat (setq n (sslength ss)); then
(setq tdata (entget (ssname ss (setq n (1- n)))))
(entmod
(subst
(cons 1 (substr (cdr (assoc 1 tdata)) 1 (-(strlen (cdr(assoc 1 tdata))) 3))) ; drop last character
(assoc 1 tdata)
tdata
)
)
)
)
)
0 Likes
Message 4 of 4

Kent1Cooper
Consultant
Consultant

@lewyee1976 wrote:

mod code to trim from last char!

....
(prompt "\nTo remove the first character from Text/Mtext,")
....

[You should also change the wording of the prompt.]

Kent Cooper, AIA
0 Likes