Lisp to change all text on a layer to same word

Lisp to change all text on a layer to same word

Anonymous
Not applicable
1,046 Views
4 Replies
Message 1 of 5

Lisp to change all text on a layer to same word

Anonymous
Not applicable

Hi all,

I'm looking for a lisp that will allow me to select all text on a personnel layer and change all the text to the same word.  Ex. I have "100 different personnel names" and I'd like to change all of them to  say"WS".  Is this possible?

0 Likes
Accepted solutions (1)
1,047 Views
4 Replies
Replies (4)
Message 2 of 5

ronjonp
Mentor
Mentor
Accepted solution

Sure:

 

(defun c:foo (/ s)
  (if (setq s (ssget ":L" '((0 . "TEXT") (8 . "personnel"))))
    (foreach e (vl-remove-if 'listp (mapcar 'cadr (ssnamex s)))
      (entmod (append (entget e) '((1 . "WS"))))
    )
  )
  (princ)
)

 

Or for no selection needed:

 

(defun c:foo (/ s)
  (if (setq s (ssget "_X" '((0 . "TEXT") (8 . "personnel"))))
    (foreach e (mapcar 'cadr (ssnamex s)) (entmod (append (entget e) '((1 . "WS")))))
  )
  (princ)
)

 

This can also be accomplished by using a little snippet like this and changing whatever property you'd like in the properties palette.

 

(sssetfirst nil (ssget "_X" '((0 . "TEXT")(8 . "personnel"))))

 

Or use the FILTER command. Many ways to skin this cat.

0 Likes
Message 3 of 5

Kent1Cooper
Consultant
Consultant

Another approach, posted mostly because it also includes Mtext  if you need that:

 

(defun C:TEST (/ ss n)
  (if (setq ss (ssget "_X" '((0 . "*TEXT") (8 . "YourLayerName"))))
    (repeat (setq n (sslength ss))
      (vla-put-TextString (vlax-ename->vla-object (ssname ss (setq n (1- n)))) "WS")
    )
  )
  (princ)
)

Kent Cooper, AIA
0 Likes
Message 4 of 5

Anonymous
Not applicable

It worked! Thanks for saving me so much time!

0 Likes
Message 5 of 5

ronjonp
Mentor
Mentor

@Anonymous wrote:

It worked! Thanks for saving me so much time!


🍻

0 Likes