lisp代码查看(功能:点到线上最近点)

(vl-load-com)
;;;========================================================*
;;;      练习                                              *
;;;功能:点到线上最近点                                    *
;;;日期:zml84 于 2008-4-26                                *
(defun C:TT (/ TEST SS TMP MODE PT PT0)
    (if (and 
            (setq SS (entsel "\n点取线: "))
            (princ "\n")
            (setq TEST t)
        )
        (while TEST 
            (setq TMP (grread 4 2) 
                  MODE (car TMP) 
                  PT (cadr TMP)
            )
            ;;(princ MODE)
            (cond 
                ;;移动 
                (
                    ;;计算最近点 
                    (setq PT0 
                        (vlax-curve-getclosestpointto 
                            (car SS) PT 
                        )
                    )
                    (princ 
                        (strcat "\r距离: " 
                            (vl-princ-to-string (distance PT PT0))
                        )
                    )
                    ;; 
                    (redraw)
                    (grdraw PT PT0 1)
                )
                ;;左击 
                (
                    ;;计算最近点 
                    (setq PT0 
                        (vlax-curve-getclosestpointto 
                            (car SS) PT 
                        )
                    )
                    ;;绘制直线 
                    (entmake 
                        (list 
                            (cons 0 "LINE")
                            (cons 62 2)
                            (cons 10 PT)
                            (cons 11 PT0)
                        )
                    )
                )
                ;;右击 
                (
                    (redraw)
                    (setq TEST NIL)
                )
                ;; 
                (t 
                    (princ 
                        (strcat "\r" (vl-princ-to-string TMP))
                    )
                )
            )
        )
    )
    (princ)
)
;;;========================================================
;;;后记:暂没有考虑选择对象的类型、坐标系的转换。
zml84 于 2024-11-23 14:01:28