Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Lisp to change all text on a layer to same word

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
Anonymous
924 Views, 4 Replies

Lisp to change all text on a layer to same word

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?

4 REPLIES 4
Message 2 of 5
ronjonp
in reply to: Anonymous

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.

Message 3 of 5
Kent1Cooper
in reply to: Anonymous

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
Message 4 of 5
Anonymous
in reply to: Anonymous

It worked! Thanks for saving me so much time!

Message 5 of 5
ronjonp
in reply to: Anonymous


@Anonymous wrote:

It worked! Thanks for saving me so much time!


:clinking_beer_mugs:

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

AutoCAD Inside the Factory


Autodesk Design & Make Report