Routine for modifying multiple Text Styles and their settings in a .dwg

Routine for modifying multiple Text Styles and their settings in a .dwg

Anonymous
Not applicable
677 Views
8 Replies
Message 1 of 9

Routine for modifying multiple Text Styles and their settings in a .dwg

Anonymous
Not applicable

I'm trying to write a routine that modifies all the Text Styles in a .dwg file by changing the SHX Font to "romans.shx", the Big Font to "special.shx". the Height to "0", and the Width Factor to "0.75".

 

The string I've written appears to work but the Text Style settings revert to their previous state after saving, closing, and reopening the .dwg.

What am I doing wrong?

Thanks.

 

(defun c:styles2one (/ styl)
(while (setq styl (tblnext "STYLE" (not styl)))
(setq styl (entget (tblobjname "STYLE" (cdr (assoc 2 styl)))))
(entmod (subst (cons 3 "RomanS") (assoc 3 styl) styl))
(entmod (subst (cons 4 "special") (assoc 4 styl) styl))
(entmod (subst (cons 40 0) (assoc 40 styl) styl))
(entmod (subst (cons 41 0.75) (assoc 41 styl) styl))
(command ".regen")
(princ))
)
0 Likes
678 Views
8 Replies
Replies (8)
Message 2 of 9

paullimapa
Mentor
Mentor

you forgot to place (setq styl in front each time you run entmod

(setq styl (entmod (subst (cons 3 "RomanS") (assoc 3 styl) styl)))
(setq styl (entmod (subst (cons 4 "special") (assoc 4 styl) styl)))
(setq styl (entmod (subst (cons 40 0) (assoc 40 styl) styl)))
(setq styl (entmod (subst (cons 41 0.75) (assoc 41 styl) styl))

Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
Message 3 of 9

Sea-Haven
Mentor
Mentor

Not sure is entupd relevant here ?

Message 4 of 9

Anonymous
Not applicable
Thank you. I've updated to include that command in each line as you suggest. I'm still seeing Styles revert to Truetype fonts though all the other settings seem to change correctly.
0 Likes
Message 5 of 9

paullimapa
Mentor
Mentor

Post sample dwg with the text styles


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 6 of 9

Anonymous
Not applicable
I don't think so, I mean I'm running regen at the end. Everything looks correct then I save and reopen the file and all the TTFs are back. Anyone?
0 Likes
Message 7 of 9

Anonymous
Not applicable

I copied in some code another person wrote for a similar problem, made a couple tweaks and it seems to work.  From what I can interpret these extended AL functions do something to the file path of something so the font can be found, or saved; I don't know.  I'm not going to act like I fully understand all these functions so any critiques are welcome.

(defun c:styles2one (/ styl)
(while (setq styl (tblnext "STYLE" (not styl)))
(setq styl (entget (tblobjname "STYLE" (cdr (assoc 2 styl)))))
(setq styl (entmod (subst (cons 3 "RomanS") (assoc 3 styl) styl)))
(setq styl (entmod (subst (cons 4 "special") (assoc 4 styl) styl)))
(setq styl (entmod (subst (cons 40 0) (assoc 40 styl) styl)))
(setq styl (entmod (subst (cons 41 0.75) (assoc 41 styl) styl)))
)
(vl-load-com)
(setq doc (vla-get-activedocument (vlax-get-acad-object)))
(setq FntPth (findfile "ROMANS.shx"))
(setq sty (vla-get-textstyles doc))
(vlax-for s sty (vla-put-fontfile s FntPth))
(if (ssget "X" '((0 . "text"))) (vlax-for n (vla-get-activeselectionset doc))
)
(command ".regen")
(princ)
)
0 Likes
Message 8 of 9

Anonymous
Not applicable

example file attached.

0 Likes
Message 9 of 9

paullimapa
Mentor
Mentor

since the visual lisp functions work, then just use that for both Romans.shx & special.shx:

 

(defun c:styles2one (/ doc FntPth FntPthB sty)
(vl-load-com)
(setq doc (vla-get-activedocument (vlax-get-acad-object)))
(setq sty (vla-get-textstyles doc))
(if (setq FntPth (findfile "ROMANS.shx"))
 (vlax-for s sty (vla-put-fontfile s FntPth))
)
(if (setq FntPthB (findfile "special.shx"))  
 (vlax-for s sty (vla-put-Bigfontfile s FntPthB))
)
(vlax-for s sty (vla-put-Width s 0.75))
(vlax-for s sty (vla-put-Height s 0.0))
;;;(if (ssget "X" '((0 . "text"))) (vlax-for n (vla-get-activeselectionset doc)))
(command "_.Regen")
(princ)
)

 

 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos