fxfeng 发表于 2016-2-2 13:32
sorry,通过高手的指点,我自己也在努力,现在实现了一部分,确实因为刚开始学,问题描述的不清不楚,我把 ...
好久不写了,针对你的图凑了一个,没做出错处理,也没仔细检查,供参考吧。
- (defun mktext(:str :pt10 :j72 / :sty) ;写文字; (setq :pt10(trans :pt10 1 0))
- (entmake
- (list
- '(0 . "TEXT")
- (cons 1 :str)
- (cons 10 :pt10)
- (cons 11 :pt10)
- (cons 7 (setq :sty(getvar "textstyle")))
- (cons 40 (getvar "textsize"))
- (cons 41 (cdr (assoc 41 (tblsearch "style" :sty))))
- (cons 51 (cdr (assoc 50 (tblsearch "style" :sty))))
- '(71 . 0)
- (cons 72 :j72)
- )
- )
- )
- (defun mkline(pt1 pt2)
- (entmake
- (list
- '(0 . "LINE")
- (cons 10 pt1)
- (cons 11 pt2)
- )
- )
- )
- (defun c:tt()
- (princ "\n标注属性程序,适用于...")
- (princ "\n选择属性块: ")
- (setq ss0 (ssget '((0 . "INSERT") (66 . 1)))
- len (sslength ss0)
- i -1
- s0 nil
- )
- (repeat len
- (setq i (1+ i)
- en(ssname ss0 i)
- s0(cons en s0)
- )
- )
- (setq pt (getpoint "\n标注基点: "))
- (setq s0 (vl-sort s0 '(lambda(x y) (< (cadr (assoc 10 (entget x))) (cadr (assoc 10 (entget y)))))))
- (setq x1 (cadr (assoc 10 (entget (car s0))))
- x2 (cadr (assoc 10 (entget (last s0))))
- x0 (car pt)
- y0 (cadr pt)
- px0(- x0 (* 2.0 (setq txh (getvar "textsize"))))
- )
- (if (< x0 x1)
- (mkline pt (list x2 y0))
- (mkline (list x1 y0) pt)
- )
- (mkline pt (polar pt (/ pi 2) (setq yh (* (+ len 1) txh 4.0))))
- (setq i 0)
- (repeat len
- (setq i (1+ i))
- (tt0 (car s0) i)
- (tt1 en i)
- (setq s0 (cdr s0))
- )
- )
- (defun tt0(en i)
- (setq et (entget en)
- ; nm (cdr (assoc 2 et))
- pti(cdr (assoc 10 et))
- xi (car pti)
- yi (cadr pti)
- ptj(list xi y0)
- )
- (mkline pti ptj)
- (if (< yi y0)
- (setq yt (- y0 (* txh 1.5)))
- (setq yt (+ y0 (* txh 0.5)))
- )
- (mktext (itoa i) (list (+ xi (* txh 0.5)) yt) 0)
- )
- (defun tt1(en i)
- (setq ts nil)
- (while
- (= (cdr (assoc 0 (setq et (entget (setq en (entnext en)))))) "ATTRIB")
- (setq txt (cdr (assoc 1 et))
- ts (cons txt ts)
- )
- )
- (setq pyi (- (+ y0 yh) (* 2.0 txh) (* 4.0 txh (- i 1)))
- pxi (+ x0 (apply 'max (mapcar '(lambda(x) (caadr (textbox (list (cons 1 x))))) ts)) txh)
- ptxi(+ x0 (* txh 0.5))
- pty1(+ pyi (* txh 0.5))
- pty2(- pyi (* txh 1.5))
- )
- (mkline (list px0 pyi) (list pxi pyi))
- (mktext (itoa i) (list (- x0 (* txh 0.5)) pty1) 2)
- (mktext (cadr ts) (list ptxi pty1) 0)
- (mktext (car ts) (list ptxi pty2) 0)
- (princ)
- )
|