- (vl-load-com)
- (defun c:test( / ent ptLst ptLstc ptLstn pt ptn pti ptt pta j i n dist l lMax)
- ;;; (setq ent (car (entsel)))
- ;;;
- ;;; ;*****获取6个点和四个角点部分,根据需要,自己改成你自己的代码******
- ;;; (repeat 6
- ;;; (setq ptLst (append ptLst (list (getpoint "\nPick a point:"))))
- ;;; )
- ;;; (repeat 4
- ;;; (setq ptLstc (append ptLstc (list (getpoint "\nPick a point:"))))
- ;;; )
- ;;; ;****************************************************************
-
- (setq pt1 '(200 1000 0) pt2 '(400 1000 0) pt3 '(500 0 0) pt4 '(200 0 0) )
- ;(setq pt1 '(200 1000 0) pt2 '(400 1000 0) pt3 '(2000 500 0) pt4 '(200 0 0) )
- (setq ptc1 '(0 1000 0) )
- (setq ptc2 '(2000 1000 0) )
- (setq ptc3 '(2000 0 0) )
- (setq ptc4 '(0 0 0) )
- (command "rectang" ptc1 ptc3)
- (setq ent (entlast))
- ;*****获取6个点和四个角点部分,根据需要,自己改成你自己的代码******
- (setq ptLst (list pt1 pt2 pt3 pt4 ))
- (setq ptLstc (list ptc1 ptc2 ptc3 ptc4))
- ;****************************************************************
- (setq ptLst (mapcar '(lambda(x) (list (vlax-curve-getDistAtPoint ent x) x)) ptLst))
- (setq ptLst (vl-sort ptLst '(lambda (x1 x2) (< (car x1) (car x2)))))
- (setq ptLstc (mapcar '(lambda(x) (list (vlax-curve-getDistAtPoint ent x) x)) ptLstc))
- (setq ptLstc (mapcar 'cadr (vl-sort ptLstc '(lambda (x1 x2) (< (car x1) (car x2))))))
- (setq i 1)
- (repeat 3
- (setq dist (append dist (list (- (car (nth i ptLst)) (car (nth (1- i) ptLst))))))
- (setq i (1+ i))
- )
- (setq lMax (apply 'max dist))
- (setq l (+ (caar ptLst) (- (vlax-curve-getDistAtParam ent (vlax-curve-getEndParam ent)) (car (last ptLst)))))
- (if (> lMax l)
- (progn
- (setq n (vl-position lMax dist))
- (repeat (1+ n)
- (setq ptLst (reverse (cons (car ptLst) (reverse (cdr ptLst)))))
- )
- )
- )
- (setq ptLst (mapcar 'cadr ptLst))
- (setq i 0)
- (repeat (1- (length ptLst))
- (setq pt (nth i ptLst))
- (setq ptn (nth (1+ i) ptLst))
- (setq ptLstn (append ptLstn (list pt)))
- (setq j 0)
- (setq m t)
- (while m
- (setq pti (nth j ptLstc))
- (cond
- ((> (vlax-curve-getDistAtPoint ent pt)
- (vlax-curve-getDistAtPoint ent ptn))
- (if (or (equal (vlax-curve-getStartPoint ent) pti 0.001)
- (< (vlax-curve-getDistAtPoint ent pti)
- (vlax-curve-getDistAtPoint ent ptn)
- ))
- (setq ptt (append ptt (list pti)))
- )
- (if (> (vlax-curve-getDistAtPoint ent pti)
- (vlax-curve-getDistAtPoint ent pt)
- )
- (setq ptt (cons pti ptt))
- )
- );1
- ((< (vlax-curve-getDistAtPoint ent pt)
- (vlax-curve-getDistAtPoint ent ptn))
- (if (and (> (vlax-curve-getDistAtPoint ent pti) (vlax-curve-getDistAtPoint ent pt))
- (< (vlax-curve-getDistAtPoint ent pti) (vlax-curve-getDistAtPoint ent ptn)))
- (setq ptt (append ptt (list pti)))
- )
- )
- );cond
- (setq j (1+ j))
- (if (> j 3) (setq m nil))
- )
- (setq ptLstn (append ptLstn ptt))
- (setq ptt nil)
- (setq i (1+ i))
- )
- (setvar "osmode" (logior (getvar "osmode") 16384))
- (command "_.pline")
- (mapcar 'command ptLstn)
- (command (last ptLst) "")
- )
|