明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1948|回复: 7

[经验] entmake创建文字样式

[复制链接]
发表于 2019-10-3 15:23 | 显示全部楼层 |阅读模式


  1. (defun c:tt(/  )
  2.   (NewStyle "国标最丑" "gbenor.shx" "gbcbig.shx" 1 0)
  3.   (NewStyle "标注样式" "romans.shx" "hzdx.shx" 0.7 15)
  4.   (NewStyle "最佳单线" "romans.shx" "hzdx.shx" 0.8 0)
  5.   (NewStyle "ttf最卡尽量少用" "simhei.ttf" "" 1 0)
  6. )
  7. ;新建文字样式:名称 英文字形 中文字体 宽度比例 倾斜角度
  8. (defun NewStyle(Name EN CN BL JD)
  9.   (if (not(tblsearch "style" Name))
  10.     (entmake
  11.       (list  
  12.         '(0 . "STYLE")
  13.         '(100 . "AcDbSymbolTableRecord")
  14.         '(100 . "AcDbTextStyleTableRecord")
  15.         (cons 2 Name)      ;文字样式名称
  16.         (cons 3 EN)    ;英文字形
  17.         (cons 4 CN)    ;中文字体
  18.         (cons 41 BL)  ;宽度比例
  19.         (cons 50 (*(/ JD 180.0)pi))  ;倾斜角度,需转化为弧度
  20.         ;'(70 . 0)    ;文字效果:0=水平,4=垂直
  21.         ;'(40 . 0)     ;文字高度
  22.         ;'(71 . 4)     ;文字效果:4=颠倒,2=反向,  6=颠倒+反向
  23.       )
  24.     )
  25.   )
  26.   (princ)
  27. )



需要注意的是在lisp中除法运算符/,参数均为整数时,结果也为整数,比如
(/ 15 180)=0 ,只有写成
(/ 15.0 180) 或者 (/ 15 180.0)  结果才为0.0833333


发表于 2019-10-3 15:57 | 显示全部楼层
本帖最后由 sachindkini 于 2019-10-3 16:03 编辑

  1. (DEFUN xcreatetextstyle  (xname$ xfont$ / res$)
  2.   (IF (= nil (TBLSEARCH "STYLE" xname$))                  ;If the text style table does not have the text style
  3.     (PROGN                          ;CASE TRUE, do the following
  4.       (SETQ res$                        ;Create a list of the style properties
  5.        (LIST
  6.          (CONS 0 "STYLE")                      ;Entity type
  7.          (CONS 100 "AcDbSymbolTableRecord")                ;Subclass marker
  8.          (CONS 100 "AcDbTextStyleTableRecord")                ;Subclass marker
  9.          (CONS 2 xname$)                      ;Style Name
  10.          (CONS 70 0)                      ;Standard flag value
  11.          (CONS 40 0)                      ;Fix text height; 0 if not fixed
  12.          (CONS 41 0.75)                      ;Text width factor
  13.          (CONS 50 0)                      ;Text oblique angle
  14.          (CONS 71 0)                      ;Text generation flags, 0-none, 2-backwards, 4-upsidedown
  15.          (CONS 42 0)                      ;Use last text height
  16.          (CONS 3 xfont$)                      rimary font file name (shx)
  17.          (CONS 4 "")                      ;Bigfont file name; blank if none
  18.        )
  19.       )
  20.       (ENTMAKE res$)                        ;Make the entity
  21.       (PRINC                          ;Report the sucessfull creation of the entity back to the user
  22.   (STRCAT
  23.     "\nSucessfully created the text style: '"
  24.     xname$
  25.     "' within the current drawing."
  26.   )
  27.       )
  28.     )                            ;End case true
  29.     (PROGN                          ;CASE FALSE, do the following
  30.       (PRINC                          ;Report the issue to the user
  31.   (STRCAT
  32.     "\nText Style: '"
  33.     xname$
  34.     "' already exists within the current drawing."
  35.   )
  36.       )                            ;
  37.     )                            ;End case false
  38.   )                            ;End if
  39. )

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

x
发表于 2019-10-3 16:12 | 显示全部楼层
annotative Text style
  1. (entmakex
  2. '(
  3.    (0 . "STYLE")
  4.    (100 . "AcDbSymbolTableRecord")
  5.    (100 . "AcDbTextStyleTableRecord")
  6.    (2 . "My TEXT")
  7.    (70 . 0)
  8.    (40 . 2.2);;<- text height
  9.    (41 . 1.0)
  10.    (50 . 0.0)
  11.    (71 . 0)
  12.    (42 . 2.2)
  13.    (3 . "arial.ttf")
  14.    (4 . "")
  15.    (-3
  16.      ("AcadAnnotative"
  17.        (1000 . "AnnotativeData")
  18.        (1002 . "{")
  19.        (1070 . 1)
  20.        (1070 . 1)
  21.        (1002 . "}")
  22.      )
  23.    )
  24. )
  25. )

 楼主| 发表于 2019-10-3 16:18 | 显示全部楼层

感觉 还是我的直观好用。
发表于 2020-8-11 20:58 | 显示全部楼层
楼主这个创建不成功啊     并没有创建相应字体 是什么情况
发表于 2024-2-12 18:17 来自手机 | 显示全部楼层
谢谢楼主分享。
发表于 2024-4-29 12:15 | 显示全部楼层
  1. (defun c:tt(/  )
  2.   
  3.   (NewStyle "国标最丑" "gbenor.shx" "gbcbig.shx" 1 0)
  4.   (NewStyle "标注样式" "romans.shx" "hzdx.shx" 0.7 15)
  5.   (NewStyle "最佳单线" "romans.shx" "hzdx.shx" 0.8 0)
  6.   (NewStyle "ttf最卡尽量少用" "simhei.ttf" "" 1 0)
  7. )

  8. (defun NewStyle (Name EN CN BL JD / styleData radian)
  9.   ;Name:文字样式名称 EN:英文字形 CN:中文字体 BL:宽度比例 JD:倾斜角度360°
  10.   ; 检查STYLE表中是否存在给定的文字样式名称
  11.   (setq styleData (tblsearch "STYLE" Name))
  12.   (if (not styleData)
  13.     (progn
  14.       ; 计算倾斜角度的弧度值
  15.       (setq radian (* (/ JD 180.0) pi))
  16.       ; 创建新的文字样式记录
  17.       (entmake
  18.         (list
  19.           '(0 . "STYLE")                           ; 实体类型
  20.           '(100 . "AcDbSymbolTableRecord")         ; 记录类型
  21.           '(100 . "AcDbTextStyleTableRecord")      ; 表样式记录类型
  22.           (cons 2 Name)                            ; 文字样式名称
  23.           (cons 3 EN)                              ; 英文字形
  24.           (cons 4 CN)                              ; 中文字体
  25.           (cons 41 BL)                             ; 宽度比例
  26.           (cons 50 radian)                         ; 倾斜角度(弧度)
  27.           (cons 40  0)                             ;文字高度(必选项)
  28.           ;(cons 70  0)                           ;文字效果:0=水平,4=垂直
  29.           ;(cons 71  4)         
  30.           ; 其他属性可以根据需要添加
  31.         )
  32.       )
  33.       (princ (strcat "文字样式创建成功: " Name))   ; 输出创建成功的消息
  34.     )
  35.     (princ (strcat "文字样式已存在: " Name))       ; 如果样式已存在,输出消息
  36.   )
  37.   (princ)                                          ; 清除命令行
  38. )

发表于 2024-6-4 16:52 | 显示全部楼层
楼主这个创建不成功,并没有创建相应字体。现在一头雾水。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-6-26 23:37 , Processed in 0.158358 second(s), 26 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表