Skipping text styles?

Skipping text styles?

DC-MWA
Collaborator Collaborator
940 Views
9 Replies
Message 1 of 10

Skipping text styles?

DC-MWA
Collaborator
Collaborator

Hi all,

I've been looking for a way to make all text styles in a drawing use "arial.ttf" font.

I've found a program that works but for some reason it skips certain text styles (seemingly random)???

Not sure why. Otherwise it works way better than the other versions i found.

Hoping someone can take a look at this and solve it.

 

thanks.

0 Likes
Accepted solutions (1)
941 Views
9 Replies
Replies (9)
Message 2 of 10

dlanorh
Advisor
Advisor
Accepted solution

Try this

 

(defun c:AllArial (/ *error* c_doc c_tstys n_font)

  (defun *error* ( msg )
    (if (not (wcmatch (strcase msg) "*BREAK*,*CANCEL*,*EXIT*")) (princ (strcat "\nOops an Error occurred : " msg)))
    (princ)
  );end_defun *error*

  (setq c_doc (vla-get-activedocument (vlax-get-acad-object))
        c_tstys (vla-get-textstyles c_doc)
        nw_font (strcat (getenv "systemroot") "\\Fonts\\Arial.ttf")
  );end_setq

  (cond (nw_font 
          (vlax-map-collection c_tstys '(lambda (x) (vlax-put-property x 'fontfile nw_font)))
          (vla-regen c_doc acallviewports)
        )
        ( (alert "Could not find Arial font"))
  );end_cond
  (princ)
);end_defun

I am not one of the robots you're looking for

0 Likes
Message 3 of 10

SeeMSixty7
Advisor
Advisor

Can you attach a sample drawing that has some styles that don't change?

0 Likes
Message 4 of 10

Kent1Cooper
Consultant
Consultant

I don't see any obvious reason.  But try this, which is not only shorter, but doesn't change the current Text Style, so it doesn't require *error* handling to change it back.  And because it doesn't use any commands, it's probably also faster, though you probably wouldn't notice the difference unless you have a pretty large number of Styles.

(defun C:ALLARIAL (/ sname sdata)
  (while (setq sname (cdr (assoc 2 (tblnext "style" (not sname)))))
    (setq sdata (entget (tblobjname "style" sname)))
    (entmod (subst '(3 . "ARIAL.TTF") (assoc 3 sdata) sdata))
  ); while
  (princ)
); defun

 

Kent Cooper, AIA
0 Likes
Message 5 of 10

DC-MWA
Collaborator
Collaborator

Hi Kent This works but when you look at the fonts in styles it looks like as if the font can't be found?

Capture.PNG

 

0 Likes
Message 6 of 10

DC-MWA
Collaborator
Collaborator

This works.

0 Likes
Message 7 of 10

DC-MWA
Collaborator
Collaborator

I've got this working. Seems to be really fast works well.

 

 

Message 8 of 10

SeeMSixty7
Advisor
Advisor

Anyway to get the drawing sample with the styles that had an issue. I enjoy tracking that kind of stuff down. grin. I'd like to know why it was and was not working with the original code.

 

Thanks.

0 Likes
Message 9 of 10

DC-MWA
Collaborator
Collaborator

Sorry, I got caught up in the heat of the moment lol

I have attached a drawing with the styles within.

 

 

 

Message 10 of 10

SeeMSixty7
Advisor
Advisor

Your lisp routine was stepping through the style table until (cdr (assoc 2 (tblnext "style"))) returned nil. Problem is it was only processing the first 4 styles in that drawing. There is a blank style entry in the style table, most likley at one point or another it was used for a linetype in the drawing. Solution to rid the drawing of this would be to assign it a name and then delete it. Caution though it could be a hack by Civil 3D for something odd. To make your lisp routine work you would simply watch for the nil style name in your code.

((0 . STYLE) (2 . Standard) (70 . 0) (40 . 2.0) (41 . 1.0) (50 . 0.0) (71 . 0) (42 . 2.0) (3 . arial.ttf) (4 . ))
((0 . STYLE) (2 . Arch-Dim) (70 . 0) (40 . 2.0) (41 . 1.0) (50 . 0.0) (71 . 0) (42 . 2.0) (3 . arial.ttf) (4 . ))
((0 . STYLE) (2 . RomanS) (70 . 0) (40 . 2.0) (41 . 1.0) (50 . 0.0) (71 . 0) (42 . 2.0) (3 . arial.ttf) (4 . ))
((0 . STYLE) (2 . MWA-med) (70 . 0) (40 . 2.0) (41 . 1.0) (50 . 0.0) (71 . 0) (42 . 2.0) (3 . arial.ttf) (4 . ))
((0 . STYLE) (2 . ) (70 . 1) (40 . 0.0) (41 . 1.0) (50 . 0.0) (71 . 0) (42 . 0.2) (3 . ltypeshp.shx) (4 . ))
((0 . STYLE) (2 . MWA-SMALL) (70 . 0) (40 . 0.0859375) (41 . 1.0) (50 . 0.0) (71 . 0) (42 . 0.0859375) (3 . arial.ttf) (4 . ))
((0 . STYLE) (2 . MWA-LG) (70 . 0) (40 . 0.1875) (41 . 1.0) (50 . 0.0) (71 . 0) (42 . 0.1875) (3 . arial.ttf) (4 . ))
((0 . STYLE) (2 . ScheduleData) (70 . 0) (40 . 0.0) (41 . 0.75) (50 . 0.0) (71 . 0) (42 . 0.09375) (3 . romans.shx) (4 . ))
((0 . STYLE) (2 . RomanSNarrow) (70 . 0) (40 . 0.0) (41 . 0.75) (50 . 0.0) (71 . 0) (42 . 1.0) (3 . romans.shx) (4 . ))
((0 . STYLE) (2 . TB_SMALL) (70 . 0) (40 . 0.0) (41 . 1.0) (50 . 0.0) (71 . 0) (42 . 0.326093) (3 . arial.ttf) (4 . ))

Here is your code updated, just in case.

(defun c:allarial (/ Oldtstyle Sttxt Userfont *error*)
  (defun *error* (s)
    (setvar "textstyle" oldtstyle)
  )
  (setq oldtstyle (getvar "textstyle"))
  (setq userfont "arial.ttf") ;_ <<<<change this for your textfont
  (setq sttxt (tblnext "style" t))
  (while sttxt 
  	 (if (cdr (assoc 2 sttxt))
  	   (progn
  	  	  (setvar "textstyle" (cdr (assoc 2 sttxt)))
          (command "._Style" "" userfont 2 1 0 "N" "N")
       )
     )
     (setq sttxt (tblnext "style"))
  )
  (setvar "textstyle" oldtstyle)
  (princ)
)

good luck.