(defun GetVertexs (e / i v lst) (setq i -1) (while (setq v (vlax-curve-getpointatparam e (setq i (1+ i)))) (setq lst (cons v lst)) ) (if (vlax-curve-isClosed e) (setq lst (cdr lst))) (reverse lst) ) ;;只对平行四边形有效,因为其他直段的多段线需要提供一个向量 (defun PointsOffset (lst di) (mapcar '(lambda (x y z / a1 a2 a p) (setq a1 (angle y x) a2 (angle y z) a (abs (- a1 a2)) ) (if (>= a pi) (setq a (/ (- (* pi 2) a) 2)) (setq a (/ a 2)) ) (setq p (mapcar '(lambda (x y) (/ (+ x y) 2)) (polar y a1 1) (polar y a2 1) )) (polar y (angle y p) (/ di (sin a))) ) (append (cdr lst) (list (car lst))) lst (append (list (last lst)) (reverse (cdr (reverse lst)))) ) ) ;;测试 (defun c:tt (/ e d ps os) (if (and (setq e (entsel)) (setq d (getdist "\n指定偏移距离: "))) (progn (setq os (getvar "osmode") ps (GetVertexs (car e)) ps (PointsOffset PS d) ) (setvar "osmode" 0) (apply 'command (cons "_.pline" ps)) (command "_close") (setvar "osmode" os) ) ) (princ) )
|