Announcements

Starting in December, we will archive content from the community that is 10 years and older. This FAQ provides more information.

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

Changing all Text styles to another text style

6 REPLIES 6
Reply
Message 1 of 7
Anonymous
785 Views, 6 Replies

Changing all Text styles to another text style

Hello,

 

Can anybody help me with the below code; I'd like to modify this code so that i can create a new text style with Arial Font and then change all text styles in a drawing to that style. Also is there a way that i can put an icon on the toolbar to have this lisp runs every time i push it?

 

(defun ChangeStyle (strStyle1 strStyle2 / entItem objBlock objDocument objItem )
 (vl-load-com)
 (setq objDocument (vla-get-activedocument (vlax-get-acad-object)))
 (if (and (tblobjname "style" strStyle1)
          (tblobjname "style" strStyle2)         
     )
  (vlax-for objBlock (vla-get-blocks objDocument)
   (if (> (vla-get-count objBlock) 0)
    (progn
     (setq objItem (vla-item objBlock 0)
           entItem (vlax-vla-object->ename objItem)
     )
     (while entItem
      (if (and (vlax-property-available-p (setq objItem (vlax-ename->vla-object entItem)) "StyleName")
               (= (strcase (vla-get-stylename objItem)) (strcase strStyle1))
          )
       (vla-put-stylename objItem strStyle2)
      )
      (setq entItem (entnext entItem))
     )
    )
   )
  )
  (princ "\nError check if styles exist: ")
 )
 (vla-regen objDocument 0)
)

 

Thanks for your help!

6 REPLIES 6
Message 2 of 7
devitg
in reply to: Anonymous

Please upload your sample.dwg 

Message 3 of 7
Anonymous
in reply to: devitg

Here you go @devitg 

 

Thanks.

Message 4 of 7
ronjonp
in reply to: Anonymous

How about something like this to apply arial.ttf to all styles :).

(defun c:foo (/ d)
  (vlax-for x (vla-get-textstyles (setq d (vla-get-activedocument (vlax-get-acad-object))))
    (vla-put-fontfile x "arial.ttf")
  )
  (vla-regen d 1)
  (princ)
)(vl-load-com)

 

Message 5 of 7
Anonymous
in reply to: ronjonp

Am I running this wrong I get a file error.

 

"Automation Error. Filer error"

Message 6 of 7
devitg
in reply to: Anonymous

Arial.ttf font file shall be at ACAD font folder. And set to your text style 

Message 7 of 7
ronjonp
in reply to: Anonymous


@Anonymous wrote:

Am I running this wrong I get a file error.

 

"Automation Error. Filer error"


Try this:

(defun c:foo (/ d ff)
  (if (findfile (setq ff (strcat (getenv "windir") "\\FONTS\\arial.ttf")))
    (progn (vlax-for x (vla-get-textstyles (setq d (vla-get-activedocument (vlax-get-acad-object))))
	     (vla-put-fontfile x ff)
	   )
	   (vla-regen d 1)
    )
    (alert (strcat ff " NOT FOUND!"))
  )
  (princ)
)
(vl-load-com)

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