Jump to content

How to Add "Bold" font style in a lisp


gilsoto13

Recommended Posts

I modified this code a little bit to get a style fixer routine. i wanted to convert selected text and mtext objects to current style (automatically loaded at the beginning) and its own settings.

 

So what I want is to make a similar routine but for Arial font style, but I have searched a little some and I can't find how to do it.

 

What I need to know is how to add the Font style "Bold" to arial font... you know... when you open the style dialog box, you can modify or create a style... and apply one of the options "Regular, bold, italic" when available according to selected style, but I cannot change those options from the command line style command... so I cannot create the arial font automatically with the bold font style applied to it... that's what I need to know how.

 

;It will fix selected text and mtext to M3 standard style format
;It will not fix adjusted mtext, run SMT and SBMT to strip mtext and nested mtext

(defun c:FIXS (/) (c:FIXSTYLE))
(defun c:fixstyle (/ OLD CO ST NEWHT TEMP OLDHT NEWWID)
(command "_.-STYLE" "standard" "simplex.shx" "0" "0.8" "0" "N" "N" "N")
(setq OLD (ssget '((-4 . "<OR") (0 . "TEXT") (0 . "MTEXT") (-4 . "OR>"))))
(if OLD
(progn
(setq ST (getvar "textstyle"))
(if (tblsearch "style" ST)
(progn (setq NEWHT (assoc 40 (tblsearch "style" ST)))
(if (not (> (cdr NEWHT) 0))
(progn (prompt "\n The style you have chosen has a preset height of 0.")
(prompt "\n The existing height of the text will be maintained.")
)
)
(setq CO 0)
(while (< CO (sslength OLD))
(progn (setq TEMP (entget (ssname OLD CO))
CO (1+ CO)
)
(if (or (= "TEXT" (cdr (assoc 0 TEMP))) (= "MTEXT" (cdr (assoc 0 TEMP))))
(progn (setq OLDHT (assoc 40 TEMP))
(setq NEWWID (assoc 41 (tblsearch "style" ST))
NEWHT (assoc 40 (tblsearch "style" ST))
)
(if (= (cdr NEWHT) 0.0)
(setq NEWHT OLDHT)
)
(setq TEMP (subst (cons 7 ST) (assoc 7 TEMP) TEMP))
(setq TEMP (subst NEWWID (assoc 41 TEMP) TEMP))
(setq TEMP (subst NEWHT (assoc 40 TEMP) TEMP))
(entmod TEMP)
)
)
)
)
)
(prompt "\n Next time select a text style that exists.")
)
)
(prompt "\n This routine works better if you select something.")
)
)
(princ)
(princ
 "\nFixstyle loaded. type \"FIXSTYLE\" or \"FIXS\" to start"
)

arial bold.jpg

Link to comment
Share on other sites

Perhaps something like this:

 

;; Args:-
;; tStyle  ~  Valid TextStyle Name
;; flags [bit-coded]
;; 0  ~  Regular
;; 1  ~  Bold
;; 2  ~  Italic

(defun PutFontStyle (tStyle flags / TypeFace Bold Italic CharSet P&Fam)
 (vl-load-com) ;; Lee Mac  ~  19.02.10

 (if (not (vl-catch-all-error-p
            (setq tStyle
              (vl-catch-all-apply
                (function vla-Item)
                  (list (vla-get-TextStyles
                          (vla-get-ActiveDocument
                            (vlax-get-acad-object))) tStyle)))))
   (progn
     (vla-getFont tStyle 'TypeFace 'Bold 'Italic 'CharSet 'P&Fam)
     (vla-SetFont tStyle  TypeFace
       (if (= 1 (logand 1 flags)) :vlax-true :vlax-false)
       (if (= 2 (logand 2 flags)) :vlax-true :vlax-false) CharSet P&Fam) t)))
     
       

     

Example of Usage:

 

(PutFontStyle "myStyle" 3) ;  ~  Sets the font for 'MyStyle' textstyle to Bold & Italic.

Link to comment
Share on other sites

Perhaps something like this:

 

;; Args:-
;; tStyle  ~  Valid TextStyle Name
;; flags [bit-coded]
;; 0  ~  Regular
;; 1  ~  Bold
;; 2  ~  Italic

(defun PutFontStyle (tStyle flags / TypeFace Bold Italic CharSet P&Fam)
 (vl-load-com) ;; Lee Mac  ~  19.02.10

 (if (not (vl-catch-all-error-p
            (setq tStyle
              (vl-catch-all-apply
                (function vla-Item)
                  (list (vla-get-TextStyles
                          (vla-get-ActiveDocument
                            (vlax-get-acad-object))) tStyle)))))
   (progn
     (vla-getFont tStyle 'TypeFace 'Bold 'Italic 'CharSet 'P&Fam)
     (vla-SetFont tStyle  TypeFace
       (if (= 1 (logand 1 flags)) :vlax-true :vlax-false)
       (if (= 2 (logand 2 flags)) :vlax-true :vlax-false) CharSet P&Fam) t)))
     
       

     

Example of Usage:

 

(PutFontStyle "myStyle" 3) ;  ~  Sets the font for 'MyStyle' textstyle to Bold & Italic.

 

 

hey Lee... thanks... I just checked your routine... and it works.. but it seems like a temporary solution... 'cause after using the routine, the style does not preserve the fontstyle Bold or Italic that was applied to some text, it could work for some tasks, but in my case, the style arial must be always set to Bold, but I can`t get it with your routine...

 

Also... I doesn't work for normal text, only mtext is being updated with the Bold type.. only arial Regular is being applied to normal text after using this routine.. :s

 

So, it works... but ... Do you know any way to make the bold fontstyle permanent for current style ('cause it's been created and set current by my routine)?

 

This is the routine I used

 

;It will fix selected text and mtext to M3 standard style format
;It will not fix adjusted mtext, run SMT and SBMT to strip mtext and nested mtext


;; SUB-FUNCTION
;; Args:-
;; tStyle  ~  Valid TextStyle Name
;; flags [bit-coded]
;; 0  ~  Regular
;; 1  ~  Bold
;; 2  ~  Italic

(defun PutFontStyle (tStyle flags / TypeFace Bold Italic CharSet P&Fam)
 (vl-load-com) ;; Lee Mac  ~  19.02.10

 (if (not (vl-catch-all-error-p
            (setq tStyle
              (vl-catch-all-apply
                (function vla-Item)
                  (list (vla-get-TextStyles
                          (vla-get-ActiveDocument
                            (vlax-get-acad-object))) tStyle)))))
   (progn
     (vla-getFont tStyle 'TypeFace 'Bold 'Italic 'CharSet 'P&Fam)
     (vla-SetFont tStyle  TypeFace
       (if (= 1 (logand 1 flags)) :vlax-true :vlax-false)
       (if (= 2 (logand 2 flags)) :vlax-true :vlax-false) CharSet P&Fam) t)))

(defun c:FIXA (/ OLD CO ST NEWHT TEMP OLDHT NEWWID)

(command "_.-STYLE" "ARIAL" "arial.ttf" "0" "1" "0" "N" "N")

(PutFontStyle "ARIAL" 1) ;  ~  Sets the font for 'ARIAL' textstyle to Bold.

(setq OLD (ssget '((-4 . "<OR") (0 . "TEXT") (0 . "MTEXT") (-4 . "OR>"))))
(if OLD
(progn
(setq ST (getvar "textstyle"))
(if (tblsearch "style" ST)
(progn (setq NEWHT (assoc 40 (tblsearch "style" ST)))
(if (not (> (cdr NEWHT) 0))
(progn (prompt "\n The style you have chosen has a preset height of 0.")
(prompt "\n The existing height of the text will be maintained.")
)
)
(setq CO 0)
(while (< CO (sslength OLD))
(progn (setq TEMP (entget (ssname OLD CO))
CO (1+ CO)
)
(if (or (= "TEXT" (cdr (assoc 0 TEMP))) (= "MTEXT" (cdr (assoc 0 TEMP))))
(progn (setq OLDHT (assoc 40 TEMP))
(setq NEWWID (assoc 41 (tblsearch "style" ST))
NEWHT (assoc 40 (tblsearch "style" ST))
)
(if (= (cdr NEWHT) 0.0)
(setq NEWHT OLDHT)
)
(setq TEMP (subst (cons 7 ST) (assoc 7 TEMP) TEMP))
(setq TEMP (subst NEWWID (assoc 41 TEMP) TEMP))
(setq TEMP (subst NEWHT (assoc 40 TEMP) TEMP))
(entmod TEMP)
)
)
)
)
)
(prompt "\n Next time select a text style that exists.")
)
)
(prompt "\n This routine works better if you select something.")
)
)
(princ)
(princ
 "\nFixarial loaded. type \"FIXA\" to start"
)

Link to comment
Share on other sites

I shall have a look at it later today Gilsoto - but in early testing, I could not seem to make it permanent either - but I'm not really sure of any other way to approach this. :geek:

Link to comment
Share on other sites

  • 11 months later...

Arial is one of those funny fonts thats a real pain to work with.

You have 1 of 2 options.

 

1) Either Create a style that has the Bold option for Arial font already on.

 

or

 

2) String cat this together with your text

 

"{\\fArial|b1|i1|c0|p34;THIS IS YOUR LINE OF TEXT}"

 

The "{\\fArial" if for the Arial Font

The "|b1" if BOLDING turned on. Use 0 if you want it off.

The "|i1" if Italisized turned on. Use 0 if you want it off.

The "|c0" and "|p34" havent figured those out yet.

so if you want a string of text or mtext to be of Arial font and Bolded; your string should look like this.

(1 . "{\\fArial|b1|i0|c0|p34;THIS IS YOUR LINE OF TEXT}")

 

hope this helps.

Link to comment
Share on other sites

  • 2 years later...

Very Good "Aporte" Nerf, all you too

 

 

 

 

Arial is one of those funny fonts thats a real pain to work with.

You have 1 of 2 options.

 

1) Either Create a style that has the Bold option for Arial font already on.

 

or

 

2) String cat this together with your text

 

"{\\fArial|b1|i1|c0|p34;THIS IS YOUR LINE OF TEXT}"

 

The "{\\fArial" if for the Arial Font

The "|b1" if BOLDING turned on. Use 0 if you want it off.

The "|i1" if Italisized turned on. Use 0 if you want it off.

The "|c0" and "|p34" havent figured those out yet.

so if you want a string of text or mtext to be of Arial font and Bolded; your string should look like this.

(1 . "{\\fArial|b1|i0|c0|p34;THIS IS YOUR LINE OF TEXT}")

 

hope this helps.

Link to comment
Share on other sites

  • 6 years later...

This is an old post but this may help someone:

 

Most TrueType fonts have multiple files for each group. One for each font style. For Arial there 9. The file for Arial Regular is Arial.ttf,  for Bold is  arialbd.ttf, for Bold/Italic it is arialbi.ttf and so on. If you place the appropriate file name in your lisp program you will get the font style you want. 

 

To find the name of the file you want go the the "C:\Windows\Font" folder, find the font you want, double click on the icon. This will display the various styles. The text below the icons will tell you which is which.  Now right click on the desired font and select "properties". The file name will appear in a text box at the top. Copy and paste the name into your lisp program and your text style will be as you want it.

Edited by RJS55
Link to comment
Share on other sites

Try this:

; Add New Text Style by Tom Beauford
(defun NewStyle (TxtStyle Font / acadApp acadDoc styles objStyle FType)
  (setq acadApp (vlax-get-Acad-object)
        acadDoc (vla-get-ActiveDocument acadApp)
        styles (vla-get-textstyles acadDoc)
        objStyle (vla-add styles TxtStyle)
        FType (vl-filename-extension Font)
  )
  (if(= ".ttf" FType)(setq Font (strcat "C:\\Windows\\Fonts\\" Font)))
  (setq Font (findfile Font))
  (princ "\nFont = ")(princ Font)(princ)
  (vla-put-fontfile objStyle Font)
  (princ)
)
;Examples:
;^C^C^P(or NewStyle (load "NewStyle.lsp"))(or(tblsearch "style" "Romans")(NewStyle "Romans" "romans.shx"))
;^C^C^P(or NewStyle (load "NewStyle.lsp"))(or(tblsearch "style" "Simplex")(NewStyle "Simplex" "simplex.shx"))
;^C^C^P(or NewStyle (load "NewStyle.lsp"))(or(tblsearch "style" "Arial")(NewStyle "Arial" "arial.ttf"))
;^C^C^P(or NewStyle (load "NewStyle.lsp"))(or(tblsearch "style" "Arial Bold")(NewStyle "Arial Bold" "arialbd.ttf"))
;^C^C^P(or NewStyle (load "NewStyle.lsp"))(or(tblsearch "style" "Arial Narrow")(NewStyle "Arial Narrow" "arialn.ttf"))
;^C^C^P(or NewStyle (load "NewStyle.lsp"))(tblsearch "style" "Swiss Lt BT")(NewStyle "Swiss Lt BT" "swissl.ttf"))

 

For quick access to the Windows Font folder load Lee Mac's http://www.lee-mac.com/open.html and run:

(LM:Open 20)

 

 

Link to comment
Share on other sites

  • 3 years later...

I was happy to find this thread because i had a hard time setting up a TextStyle that had a fixed Bold parameter.

We're using «Microsoft Sans Serif Normal» in our plans (micross.ttf) and Windows 10 (by default, at least) doesn't have a bold micross TTF file installed.

We used to be forced to use MTEXT instead of DTEXT in order to have bold characters.

 

I ended up copying our regular TextStyle (using micross.ttf) and renaming it with suffix "_Bold" and i used Lee's function to make that TextStyle bold.

it worked like a charm and all existing and new Texts or Mtexts are showned and plotted correctly according to the Bold and normal Textstyles.

 

I'm using BricsCAD V21 and the changes to the Bold TextStyle seems to be permanent and saved in the drawing... i wonder if this behavior changed since 2010, because i'm having no problem with this.

 

So thanks @Lee Mac and @gilsoto13

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...