Using Visual LISP, how do you create a new style without using (command "style" new-style full-style-name "" "" "" "" "" "") ?
There are two lisp approaches to create a new style, without using (command "style"...etc), but you will need the name of the actual .ttf file to do so. Before we get into the two approaches, one important point to note. It seems that with some fonts, mostly Swiss and Dutch, the font name is abbreviated in AutoCAD's STYLE dialog. Some of the common abbreviations used are:
Bd = Bold
Blk = Black
Cn = Condensed
Ex = Extended
It = Italic
Out = Outline
Rm = Roman
Xbd = Extra Bold
For example:
Swis721 BlkEx BT would be written as Swiss 721 Black Extended BT
Swis721 BdCnOut BT would be written as Swiss 721 Bold Condensed Outline BT
Dutch801 Rm BT would be written as Dutch 801 Roman BT
Dutch801 Xbd BT would be written as Dutch 801 Extra Bold BT
Note: Using Windows Explorer, you can see the actual spelling of the font names, in the Fonts directory (ex: C:\Windows\Fonts).
Again, Windows' Fonts directory lists the font names and the related .ttf filename. For example: Swiss 721 Bold Condensed Outline BT is found in the file swisscbo.ttf. With this information, we can proceed to entmake a new text style. First, the old AutoLISP approach, using entmake:
;;Style: myNewStyle
;;Font Name: Swiss 721 Bold Condensed Outline BT
;;Fontfile: swisscbo.ttf
(if (not (tblsearch "STYLE" "myNewStyle"))
(entmake '((0 . "STYLE")
(100 . "AcDbSymbolTableRecord")
(100 . "AcDbTextStyleTableRecord")
(2 . "myNewStyle") ;style name
(3 . "swisscbo.ttf") ;font file
(70 . 0)
(40 . 0.0)
(41 . 1.0)
(50 . 0.0)
(71 . 0)
)
)
(princ "\n Style already defined")
)
The Visual LISP (ActiveX) approach is as follows:
;;Style: myNewStyle
;;Font Name: Swiss 721 Bold Condensed Outline BT
;;Fontfile: swisscbo.ttf
(vl-load-com)
(setq acadApp (vlax-get-Acad-object))
(setq acadDoc (vla-get-ActiveDocument acadApp))
(setq styles (vla-get-textstyles acadDoc))
;; Add the style named "myNewStyle"
(setq objStyle (vla-add styles "myNewStyle"))
;; Assign fontfile "swisscbo.ttf" to the style
(setq ff "c:\\winnt\\fonts\\swisscbo.ttf") ;your path may be different
(vla-put-fontfile objStyle ff)
;; Optional: Make the new style Active
(vla-put-activetextstyle acadDoc objStyle)
(princ)