- (defun c:FitPl
- (/ ENT FGX VERTEXSNUM N SECDEV PLIST D1 D2 D K D0 PARAM obj)
- ;;直线拟合多段线 By Gu_xl
- (while (not (setq ent (car (entsel "\n选择多段线:")))))
- (setq obj (vlax-ename->vla-object ent))
- (setq fgx (getdist "\n输入最小分割间距<0.5>:"))
- (if (null fgx)
- (setq fgx 0.5)
- )
- (setq vertexsNum
- (fix (vlax-curve-getEndParam ent))
- n 0
- )
- (repeat vertexsNum
- (if (setq secdev (vlax-curve-getSecondDeriv ent n))
- (if (equal '(0.0 0.0 0.0) secdev 1e-8)
- (setq plist (cons (vlax-curve-getPointAtParam ent n) plist))
- (progn
- (setq d1 (vlax-curve-getdistAtParam ent n)
- d2 (vlax-curve-getdistAtParam ent (1+ n))
- d (- d2 d1)
- k (fix (/ d fgx))
- d0 (/ 1.0 (1+ k))
- param n
- )
- (setq plist (cons (vlax-curve-getPointAtParam ent n) plist))
- (if (equal d0 1.0 0.001)
- (setq plist
- (cons (vlax-curve-getPointAtParam ent (+ 0.5 param))
- plist
- )
- )
- (repeat k
- (setq plist (cons (vlax-curve-getPointAtParam
- ent
- (setq param (+ param d0))
- )
- plist
- )
- )
- )
- )
- )
- )
- )
- (setq n (1+ n))
- )
- (if (not (vlax-curve-isClosed ent))
- (setq plist (cons (vlax-curve-getEndPoint ent) plist))
- )
- (reverse plist)
- (command "pline")
- (foreach p plist
- (command "_non" (trans p 0 1))
- )
- (command "")
- (if (vlax-curve-isClosed obj)
- (vla-put-closed
- (vlax-ename->vla-object (entlast))
- :vlax-true
- )
- )
- (princ)
- )
|