Hello,
I am trying to put together a LISP that changes the font of two text styles. One bing named "Standard", and the other "WD".
This is what I have so far...
(defun C:CHANGESTYLE (/ entities len count ent ent_data ent_name new_style_name) (command "STYLE" "Standard" "Romantic" "" "" "" "" "") (setq entities (ssget "X" '((0 . "TEXT"))) len (sslength entities) count 0 );setq (while (< count len) (setq ent (ssname entities count) ent_data (entget ent) ent_name (cdr (assoc 7 ent_data)) );setq (setq new_style_name (cons 7 "Standard")) (setq ent_data (subst new_style_name (assoc 7 ent_data) ent_data)) (entmod ent_data) (setq count (+ count 1)) );while ;;;runs same routine again, picking up Mtext this time. (setq entities (ssget "X" '((0 . "MTEXT"))) len (sslength entities) count 0 );setq (while (< count len) (setq ent (ssname entities count) ent_data (entget ent) ent_name (cdr (assoc 7 ent_data)) );setq (setq new_style_name (cons 7 "Standard")) (setq ent_data (subst new_style_name (assoc 7 ent_data) ent_data)) (entmod ent_data) (setq count (+ count 1)) );while (princ) );defun
I couldn't figure out how to select mtext and text all in one swoop, so i ran it twice
Now, when i run this code, i get the following error "lselsetp nil".
Any advice is appreciated.
Thanks!
Solved! Go to Solution.
Solved by Kent1Cooper. Go to Solution.
@Anonymous wrote:
....
I couldn't figure out how to select mtext and text all in one swoop, so i ran it twice ....
... when i run this code, i get the following error "lselsetp nil".
....
You can search for more than one entity type, with (wcmatch)-like syntax, either putting entity names together with comma separators:
(setq entities (ssget "X" '((0 . "TEXT,MTEXT")))
or using wildcards:
(setq entities (ssget "X" '((0 . "*TEXT")))
[The latter would also find RTEXT, if you ever use that.]
After that selection, you can avoid that error message when there aren't any of that entity type, with:
(if entities
(progn ; then
(setq
len (sslength entities)
count 0
);setq
(while ....
; .... process stuff ....
); while
); progn
); if
@Anonymous wrote:
Very nice.
Thank you good sir!
You're welcome. Read up on (wcmatch) to see other wild-card options with which you can refine (ssget) selections.
@Anonymous are you able to post your CHANGESTYLE lisp routine with @Kent1Cooper's fixes?
I have a big client who just was bought by an even bigger client. We will likely have thousands of drawings that will need to have all the styles changed to match this new client's style. I know there must be a way to do this with LISP but I can't seem to find anything that will change all annotative styles.
Any help is very much appreciated - wish I knew more about programming. Where else could I look for LISP routines other than this website I wonder.
It has been some time, but I believe this was the final version I used back then...
(defun C:CHANGESTYLE (/ entities len count ent ent_data ent_name new_style_name) (command "STYLE" "Standard" "Romantic" "" "" "" "" "") (setq entities (ssget "X" '((0 . "*TEXT"))) len (sslength entities) count 0 );setq (while (< count len) (setq ent (ssname entities count) ent_data (entget ent) ent_name (cdr (assoc 7 ent_data)) );setq (setq new_style_name (cons 7 "Standard")) (setq ent_data (subst new_style_name (assoc 7 ent_data) ent_data)) (entmod ent_data) (setq count (+ count 1)) );while ;;;runs same routine again, picking up Mtext this time. );defun
Can't find what you're looking for? Ask the community or share your knowledge.