手痒,写了一个。。。也请高手们修改修改。。。

- ;;;通用函数 carrot1983.2007-12-12
- (vl-load-com)
- ;;ss->elst选择集->图元表
- (defun ss->elst (ss / elst)
- (setq i 0)
- (repeat (sslength ss)
- (setq elst (cons (ssname ss i) elst)
- i (1+ i)
- )
- )
- (reverse elst)
- )
- ;;;按顺序取得曲线的点
- (defun jw-get-plst (E / I O PLST)
- (setq o (vlax-ename->vla-object e)
- i 1
- plst nil
- )
- (repeat 100
- (if (and o (setq p (vlax-curve-getPointAtParam o i)))
- (setq plst (cons p plst)
- i (1+ i)
- )
- (setq o nil)
- )
- )
- plst
- )
- ;;;写线jw-make-line
- (defun jw-make-line (v10 v11)
- (entmake (list (cons 0 "LINE")
- (cons 6 "BYLAYER")
- (cons 8 "0")
- (cons 10 v10)
- (cons 11 v11)
- (cons 39 0.0)
- (cons 62 256)
- (cons 210 (list 0.0 0.0 1.0))
- )
- )
- )
- ;;;中点jw-mid-p
- (defun jw-mid-p (a b)
- (mapcar
- '(lambda (a b) (/ (+ a b) 2))
- a
- b
- )
- )
- ;;;中点表jw-mid-plst
- (defun jw-mid-plst (E DIS / ANG13 ANG24 DIS1 DIS2 P1 P2 P3 P4 PLST)
- (setq plst (jw-get-plst e))
- (setq p1 (mid-p (nth 0 plst) (nth 1 plst))
- p2 (mid-p (nth 1 plst) (nth 2 plst))
- p3 (mid-p (nth 2 plst) (nth 3 plst))
- p4 (mid-p (nth 3 plst) (nth 0 plst))
- )
- (setq ang13 (angle p1 p3)
- ang24 (angle p2 p4)
- )
- (setq dis1 dis
- dis2 dis
- )
- (setq p1 (polar p1 (+ ang13 pi) dis1)
- p2 (polar p2 (+ ang24 pi) dis2)
- p3 (polar p3 ang13 dis1)
- p4 (polar p4 ang24 dis2)
- )
- (setq plst (list p1 p2 p3 p4))
- )
- ;;;主程序:tt画矩形中心线carrot1983.2007-12-12
- (defun c:tt (/ ELST SS D E I PLST)
- (if (setq ss (ssget '((0 . "*POLYLINE"))))
- (progn
- (setq elst (ss->elst ss))
- (if (setq d (getdist "\n指定伸出矩形外长度<100>"))
- d
- (setq d 100)
- )
- (foreach e elst
- (setq plst (jw-mid-plst e d))
- (jw-make-line (nth 0 plst) (nth 2 plst))
- (jw-make-line (nth 1 plst) (nth 3 plst))
- )
- )
- (alert "\n请重新选择!")
- )
- (princ)
- )
|