AutoLISP以直线为基线添加文字
2011-03-28 17:12 精诚所至 金石为开 阅读(495) 评论(0) 编辑 收藏 举报AutoLISP以直线为基线添加文字,代码如下。
(defun c:test()
(setvar "cmdecho" 0)
(setq os (getvar "osmode"))
(setvar "osmode" 0)
(setq en (car (entsel "\n选取线:")))
(setq pt10 (cdr (assoc 10 (entget en))))
(setq pt11 (cdr (assoc 11 (entget en))))
(setq dd (distance pt10 pt11))
(setq shh (getvar "textsize"))
(princ (strcat "\n线段长度=:" (rtos dd 2)))
(setq str_hh (strcat "\n文字高度<" (rtos shh 2) ">:"))
(setq hh (getdist pt10 str_hh))
(if (null hh) (setq hh shh))
(setq txt (getstring "\n文字内容:"))
(setq ang (angle pt10 pt11))
(setq i 1 txtpt pt10)
(setq nn (1- (strlen txt)))
(repeat (1+ nn)
(setq stxt (substr txt i 1))
(command "text" "c" txtpt hh (* (/ ang pi) 180) stxt)
(setq txtpt (polar txtpt ang (/ dd nn)))
(setq i (1+ i))
)
(setvar "osmode" os)
)
代码完。
从第一点到第二点看,文字只能再直线的左侧。
![](https://img2024.cnblogs.com/blog/35695/202408/35695-20240825082459112-376424429.jpg)