(defun sort-pt-1 (plts fun n)
(vl-sort plts
'(lambda (a b)
(fun (nth n a) (nth n b))
)
)
)
(defun sort-pt (plst xyz / fun)
(setq xyz (vl-string->list xyz))
(foreach n-xyz (reverse xyz)
(if (< n-xyz 100)
(setq fun >
n-xyz (- n-xyz 88)
plst (sort-pt-1 plst fun n-xyz)
)
(setq fun <
n-xyz (- n-xyz 120)
plst (sort-pt-1 plst fun n-xyz)
)
)
)
)
;-------------------------------------------------
(defun C:hdm (/ S1 S2 I)
(setq en (entsel "选择一条直线:"))
;(setq size 0.1)
(SETQ S1 (ssget '((0 . "
OINT"))))
(SETQ n 0)
(repeat (sslength s1)
(setq lst (cons (ssname s1 n) lst)
n (1+ n)
)
)
(setq
x (mapcar '(lambda (x) (car (cdr (assoc 10 (entget x))))) lst)
)
(setq
y (mapcar '(lambda (x) (cadr (cdr (assoc 10 (entget x)))))
lst
)
)
(setq maxx (eval (cons 'max x))
minx (eval (cons 'min x))
)
(setq maxy (eval (cons 'max y))
miny (eval (cons 'min y))
)
(setq dx (- maxx minx)
dy (- maxy miny)
)
(if (> dx dy)
;;x坐标排序:
(setq S2 (sort-pt-1 s1 "x"))
;;y坐标排序:
(setq S2 (sort-pt-1 s1 "y"))
)
(progn
(setq I 0)
(repeat (sslength S2)
(setq pen_data (entget (ssname s2 i)))
(setq ppt (assoc 10 pen_data))
(setq pp (cdr ppt))
(setq 
erpt (vlax-curve-getClosestPointTo (car en) pp T))
;找出垂点
(entmake (APPEND '((0 . "LINE")
(100 . "AcDbEntity")
(100 . "AcDbLine")
(8 . "0")
)
(LIST (CONS 10 pp) (CONS 11 perpt))
)
)
(princ "\n")
(princ (cdddr (assoc 10 (entget (ssname S2 I)))))
;显示排序结果。
(setq I (1+ I))
)
)
(princ)
)