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

LISP to change text style

5 REPLIES 5
SOLVED
Reply
Message 1 of 6
Anonymous
19919 Views, 5 Replies

LISP to change text style

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 Smiley Wink

Now, when i run this code, i get the following error "lselsetp nil".

 

Any advice is appreciated.

Thanks!

5 REPLIES 5
Message 2 of 6
Kent1Cooper
in reply to: Anonymous


@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

 

Kent Cooper, AIA
Message 3 of 6
Anonymous
in reply to: Kent1Cooper

Very nice.

Thank you good sir!

Message 4 of 6
Kent1Cooper
in reply to: Anonymous


@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.

Kent Cooper, AIA
Message 5 of 6
chase.gifford
in reply to: Anonymous

@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.

Message 6 of 6
Anonymous
in reply to: chase.gifford

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.

Post to forums  

AutoCAD Inside the Factory


Autodesk Design & Make Report