为了好玩。。。
- (defun AT:ClosestPoint (ep / _next _dist ep el lst)
- ;; Return closest point to selected entity
- ;; ep - entity and point list
- ;; Alan J. Thompson, 09.14.10
- (defun _next (e / p)
- (if (and (setq e (entnext e)) (setq p (cdr (assoc 10 (entget e)))))
- (cons p (_next e))
- )
- )
- (defun _dist (a b) (distance (list (car a) (cadr a)) (list (car b) (cadr b))))
- (if
- (and (vl-consp ep)
- (eq (type (car ep)) 'ENAME)
- (or (eq 1 (getvar 'worlducs)) (setq ep (list (car ep) (trans (cadr ep) 1 0))))
- (cond
- ((vl-position (cdr (assoc 0 (setq el (entget (car ep))))) '("ARC" "LINE" "SPLINE"))
- (setq lst (list (vlax-curve-getStartPoint (car ep)) (vlax-curve-getEndPoint (car ep))))
- )
- ((eq (cdr (assoc 0 el)) "LWPOLYLINE")
- (foreach p el (and (eq (car p) 10) (setq lst (cons (cdr p) lst))))
- lst
- )
- ((eq (cdr (assoc 0 el)) "POLYLINE") (setq lst (_next (car ep))))
- )
- )
- (car (vl-sort lst (function (lambda (a b) (< (_dist a (cadr ep)) (_dist b (cadr ep)))))))
- )
- )
eg。
- (defun c:Test (/ p)
- (if (setq p (AT:ClosestPoint (entsel "\nSelect curve: ")))
- (entmake (list '(0 . "CIRCLE") (cons 10 p) '(40 . 10.)))
- )
- (princ)
- )
|