Announcements

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

Changing all Text styles to another text style

Anonymous

Changing all Text styles to another text style

Anonymous
Not applicable

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!

0 Likes
Reply
788 Views
6 Replies
Replies (6)

devitg
Advisor
Advisor

Please upload your sample.dwg 

0 Likes

Anonymous
Not applicable

Here you go @devitg 

 

Thanks.

0 Likes

ronjonp
Advisor
Advisor

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)

 

Anonymous
Not applicable

Am I running this wrong I get a file error.

 

"Automation Error. Filer error"

0 Likes

devitg
Advisor
Advisor

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

0 Likes

ronjonp
Advisor
Advisor

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