本帖最后由 359321852 于 2024-1-31 08:41 编辑
谢谢你的帮助,
在你的基础上也做了一些修改,增加了获取文字高度,和设置
- (defun c:tt (/ ss ent lis)
- ;多段线每段线中心标注本段线长
- (setq ss (ssget ":P:E" '((0 . "LWPOLYLINE"))))
- (setq h1 (getvar "TEXTSIZE"));获取文本高度
- (setq h (getreal (strcat "\n请键入文字高度<" (rtos h1 2 2) ">:")))
- (if (null h)
- (setq h h1)
- )
- (setvar"textsize" h);设置文本高度
- (setq ent (ssname ss 0))
- (mapcar
- '(lambda (x)
- (setq pt (cadr x))
- (setq an (last x))(print an)
- (setq an (if (>= (* pi 1.5) an (* pi 0.5)) (- an pi) an))
- (setq pt (polar pt (+ an (* pi 0.5)) h));偏离一个文字的高度距离
- (entmake
- (list '(0 . "TEXT") '(72 . 1) '(73 . 2)
- (cons 1 (car x))
- (cons 10 pt)
- (cons 11 pt)
- (cons 40 h)
- (cons 50 an)
- )
- )
- )
- (mapcar
- '(lambda (x)
- (list
- (rtos (distance (car x) (cadr x)) 2 2)
- (mapcar '* '(0.5 0.5) (mapcar '+ (car x) (cadr x)))
- (- (rem (+ (angle (car x) (cadr x)) (* 0.25 pi)) pi) (* 0.25 pi))
- )
- )
- (if (vlax-curve-isClosed ent)
- (mapcar 'list
- (setq lis (mapcar 'cdr (vl-remove-if-not '(lambda (x)(= 10 (car x)))(entget ent))))
- (append (cdr lis) (list (car lis)))
- )
- (reverse
- (cdr
- (reverse
- (mapcar 'list
- (setq lis (mapcar 'cdr (vl-remove-if-not '(lambda (x)(= 10 (car x)))(entget ent))))
- (append (cdr lis) (list (car lis)))
- )
- )
- )
- )
- )
- )
- )
- (princ)
- )
|