Starting in December, we will archive content from the community that is 10 years and older. This FAQ provides more information.
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!
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 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.