Author Topic: changing font of text style at startup  (Read 6782 times)

0 Members and 1 Guest are viewing this topic.

rkitek

  • Guest
changing font of text style at startup
« on: September 19, 2005, 02:30:09 PM »
Our office recently decided to change our 'standard' font from a TTF to a SHX. Rather than tediously going drawing by drawing to changing the font definition w/ 'style', I thought it would be nice if I could make the font change upon opening the dwg. I'm having a little trouble getting it to work, so any help would be much appreciated...

Basically, I'm trying to get all styles w/ font 'cgor45x.ttf' be replaced w/ 'cgor45x.shx'. The ttf font actually is listed in the flyout as "CG Omega"

Here's what I've got now:
Code: [Select]
(VL-LOAD-COM)
   (SETQ *DOC*
      (VLA-GET-ACTIVEDOCUMENT
      (VLAX-GET-ACAD-OBJECT)
      )
   )
   (SETQ STYLES
      (VLA-GET-TEXTSTYLES *DOC*)
   )
   (VLAX-FOR STYLE STYLES
      (IF (= (VLA-GET-FONTFILE STYLE) "CG Omega") ;;;I also tried "cgor45xf.ttf"
      (VLA-PUT-FONTFILE STYLE "cgor45xf.shx"))
   )

Am I way off here? Thanks in advance.

Sdoman

  • Guest
Re: changing font of text style at startup
« Reply #1 on: September 19, 2005, 03:36:33 PM »
Try setting the textstyle you want to modify active, then run the following code:

(vlax-dump-object  (vla-get-activetextstyle *doc*) t)

The report generated should show what the font file name is.  Also, beware of string case when comparing strings.

(IF (= (strcase (VLA-GET-FONTFILE STYLE)) "YOURFONT.TTF")...



CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: changing font of text style at startup
« Reply #2 on: September 19, 2005, 04:56:08 PM »
Yep, that should do it...
Here is another way to wrap it.
Code: [Select]
(defun c:style_Update (/ st)

  (vl-load-com)

  (vlax-for st
               (vla-get-textstyles
                 (vla-get-activedocument (vlax-get-acad-object))
               )
    ;;  Old font file in CAPS
    (if (= (strcase (vla-get-fontfile st)) "CGOR45XF.TTF")
      (vla-put-fontfile st "cgor45xf.shx") ; New font file name
    )
  )
  (princ)
)

(c:style_Update) ; run it
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

rkitek

  • Guest
Re: changing font of text style at startup
« Reply #3 on: September 19, 2005, 05:17:03 PM »
Thanks for your help, works perfectly now!

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: changing font of text style at startup
« Reply #4 on: September 19, 2005, 05:34:47 PM »
Heh, CAB,

Just a comment to acknowledge how much your code has changed in the last couple of years.

I know you may come over all blushy and blame some of the guys here, but I see it primarily as a result of the effort you put in.

great stuff !!

Regards
Kerry
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: changing font of text style at startup
« Reply #5 on: September 19, 2005, 05:56:12 PM »
Thank you sir. :-)

If you hang around here & AUGI long enough you gota learn somethin.
As you said I do practice a lot. Although posting a lot of code shows your
progress you risk a failure now & then. But I think it's worth the risk.

Now if I could only learn to spel. :-D
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Hugo

  • Bull Frog
  • Posts: 430
Re: changing font of text style at startup
« Reply #6 on: November 12, 2012, 08:23:43 AM »
For me this does not work, the style is not changed.
Please help

Bei mir funktioniert das nicht der Stil wird nicht geändert.
Bitte um Hilfe


Code: [Select]
(defun c:style_Update (/ st)

  (vl-load-com)

  (vlax-for st
               (vla-get-textstyles
                 (vla-get-activedocument (vlax-get-acad-object))
               )
    ;;  Old font file in CAPS
    (if (= (strcase (vla-get-fontfile st)) "ARIAL UNICODE MS.tff")  ;;"ARIALUNI.TTF")
      (vla-put-fontfile st "ARIAL.ttf") ; New font file name
    )
  )
  (princ)
)

(c:style_Update) ; run it

Because the font is much too large
Denn die Schrift ist viel zu gross

Why is the font does not replace what is wrong
Thank you

Warum wird die Schrift nicht ersetzt wo liegt der Fehler
Danke
« Last Edit: November 14, 2012, 12:42:39 AM by Hugo »

Hangman

  • Swamp Rat
  • Posts: 566
Re: changing font of text style at startup
« Reply #7 on: November 14, 2012, 02:58:51 PM »
Hello Hugo,

Just a guess here as I'm not quite proficient with vlisp yet but you have the code
Code: [Select]
(if (= (strcase (vla-get-fontfile st))Notice the keyword "strcase" which means you are matching the font by the case (upper case, lower case)
So the question here then 'is your fonts lower case or upper case?'
Code: [Select]
"ARIAL UNICODE MS.tff"  This is uppercase with a lowercase extension ".ttf"
Code: [Select]
"ARIALUNI.TTF"  This is uppercase all the way.

Perhaps I am misleading here, but according to the 'help' files,
Quote
strcase, Returns a string where all alphabetic characters have been converted to uppercase or lowercase
Hangman  8)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Drafting Board, Mechanical Arm, KOH-I-NOOR 0.7mm
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Hugo

  • Bull Frog
  • Posts: 430
Re: changing font of text style at startup
« Reply #8 on: November 15, 2012, 12:57:47 AM »
Hallo Hangman

That's also not get the following error

Quote
Befehl: STYLE_UPDATE
; Fehler: Automatisierungsfehler Dateifehler

Das ist es auch nicht bekomme folgende Fehlermeldung

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: changing font of text style at startup
« Reply #9 on: November 15, 2012, 10:14:07 AM »
Try this:
Code: [Select]
;;  returns nil if not found, else font name if found
;;  TTF file names should have the extension already added
;;  "romant.ttf"
(defun find_font (fname / path font$)
  (setq path (getenv "windir"))
  (if (vl-position (substr path (strlen path)) '("/" "\\"))
    (setq path (strcat path "FONTS\\"))
    (setq path (strcat path "\\FONTS\\"))
  )
  (setq font$ (if (wcmatch fname "*\\*,*`.*")
                fname
                (strcat fname ".shx")
              )
  )

  (cond
    ((findfile font$) font$)
    ((and path (findfile (strcat path font$))) font$)
    (t nil)
  )
)

(find_font "ARIALUNI.TTF")
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: changing font of text style at startup
« Reply #10 on: November 15, 2012, 10:19:41 AM »
As Hangman suggested:
Code: [Select]
(defun c:style_update (/ st)
  (vl-load-com)
  (vlax-for st (vla-get-textstyles (vla-get-activedocument (vlax-get-acad-object)))
    ;;  Old font file in CAPS
    (if (= (strcase (vla-get-fontfile st)) "ARIAL UNICODE MS.TTF")
      ;;"ARIALUNI.TTF")
      (vla-put-fontfile st "ARIAL.ttf") ; New font file name
    )
  )
  (princ)
)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Lee Mac

  • Seagull
  • Posts: 12913
  • London, England
Re: changing font of text style at startup
« Reply #11 on: November 15, 2012, 10:59:48 AM »
@CAB,
Here is an alternative method to retrieve the Fonts path:

Code - Auto/Visual Lisp: [Select]
  1. ;; Special Folder  -  Lee Mac
  2. ;; Queries the WshSpecialFolders collection for the specified folder
  3. ;; Ref: http://msdn.microsoft.com/en-us/library/9x9e7edx%28v=vs.85%29.aspx
  4.  
  5. (defun LM:SpecialFolder ( folder / res spf wsh )
  6.     (setq res
  7.         (vl-catch-all-apply
  8.             (function
  9.                 (lambda ( )
  10.                     (setq wsh (vlax-get-or-create-object "wscript.shell")
  11.                           spf (vlax-get-property wsh 'specialfolders)
  12.                     )
  13.                     (vlax-invoke-method spf 'item folder)
  14.                 )
  15.             )
  16.         )
  17.     )
  18.     (if spf  (vlax-release-object  spf))
  19.     (if wsh  (vlax-release-object  wsh))
  20.     (if (not (vl-catch-all-error-p res))
  21.         res
  22.     )
  23. )

Code - Auto/Visual Lisp: [Select]
  1. _$ (LM:SpecialFolder "Fonts")
  2. "C:\\Windows\\Fonts"

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: changing font of text style at startup
« Reply #12 on: November 15, 2012, 11:18:31 AM »
Thanks Lee  8-)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Hugo

  • Bull Frog
  • Posts: 430
Re: changing font of text style at startup
« Reply #13 on: November 16, 2012, 03:05:13 AM »
Hallo CAB

Scripture is found.


Quote
Befehl: (find_font "ARIALUNI.TTF")
"ARIALUNI.TTF"


Schrift wird gefunden.

eldanimal

  • Mosquito
  • Posts: 16
Re: changing font of text style at startup
« Reply #14 on: November 05, 2017, 03:15:42 PM »
I think I am having problems similar to Hugo, and mein Deutsch ist nicht so gut, but I'm not sure this thread fixed his problem.

I am using the following w/ just modified fonts from CAB's original code w/out success:

(defun c:style_Update (/ st)

  (vl-load-com)

  (vlax-for st
               (vla-get-textstyles
                 (vla-get-activedocument (vlax-get-acad-object))
               )
    ;;  Old font file in CAPS
    (if (= (strcase (vla-get-fontfile st)) "SIMSUNB.TTF")
      (vla-put-fontfile st "SIMSUN.TTC") ; New font file name
    )
  )
  (princ)
)

(c:style_Update) ; run it

On load I get the following: ; error: Automation Error. Filer error
This is the same as: ; Fehler: Automatisierungsfehler Dateifehler

Also, Hugo's translator read that "Scripture is found", and that sure sounds like a resolution....Amen, Amen, but I think he really meant that the find_font script is just finding the Font.

I have also run the find_font script on both of the attached, neither finds "SIMSUN" and both find "SIMSUN.TTC", but the style_update script is not working on either.

I also tried removing strcase from the style_update script, and the filer error disappeared, but the results did not change.

Thank you all for any help,
Dan