Lisp lệnh KCTT trong chủ đề “Nhờ viết Lisp xác định lý trình và khoảng cách tới tim”
Ngồi cả buổi tối chắp vá cóp nhặt từ các lisp lại thì được kết quả thế này, đưa lên cho ae nào cần thì dùng tạm vậy:
(defun c:KCTT( / oidos olddim e obj PL pr pt pt1 dis i) (vl-load-com) (command "CMDECHO" 0) (command "undo" "be") (setq oldos (getvar "osmode")) (setvar "osmode" 0) (setq olddim (getvar "dimzin")) (setvar "dimzin" 0) (setq e (car (entsel "\nChon tim tuyen"))) (setq obj (vlax-ename->vla-object e)) (HLI e) (setq PL (car (entsel "\nChon duong PL"))) (setq pr (vlax-curve-getEndParam PL) i 0) (HLI PL) (setq fn (getfiled "Chon file de ghi ket qua" "" "CSV" 1) fid (open fn "w") ) (while (<= i pr) (setq pt (vlax-curve-getPointAtParam PL i)) (setq pt1 (vlax-curve-getClosestPointTo obj pt)) (setq dis (distance pt pt1)) (setq i (1+ i)) (princ dis fid) (princ "\n" fid) ) (close fid) (setvar "dimzin" olddim) (setvar "osmode" oldos) (command "undo" "end") (Princ) ) ;--------------------------------- (defun HLI(enT) (sssetfirst (ssadd enT (ssadd)) (ssadd enT (ssadd))) )
- Tải lisp
- 401460_kctt.lsp
Cách dùng
- Tải tệp 401460_kctt.lsp về máy.
- Trong AutoCAD gõ lệnh APPLOAD, chọn tệp vừa tải rồi bấm Load. Cũng có thể kéo thả tệp .lsp vào cửa sổ bản vẽ.
- Gõ lệnh KCTT để chạy lisp.
Mã nguồn 401460_kctt.lsp
;; free lisp from cadviet.com
;;; this lisp was downloaded from https://www.cadviet.com/forum/topic/81402-nh%E1%BB%9D-vi%E1%BA%BFt-lisp-x%C3%A1c-%C4%91%E1%BB%8Bnh-l%C3%BD-tr%C3%ACnh-v%C3%A0-kho%E1%BA%A3ng-c%C3%A1ch-t%E1%BB%9Bi-tim/
(defun c:KCTT( / oidos olddim e obj PL pr pt pt1 dis i)
(vl-load-com)
(command "CMDECHO" 0)
(command "undo" "be")
(setq oldos (getvar "osmode"))
(setvar "osmode" 0)
(setq olddim (getvar "dimzin"))
(setvar "dimzin" 0)
(setq e (car (entsel "\nChon tim tuyen")))
(setq obj (vlax-ename->vla-object e))
(HLI e)
(setq PL (car (entsel "\nChon duong PL")))
(setq pr (vlax-curve-getEndParam PL) i 0)
(HLI PL)
(setq fn (getfiled "Chon file de ghi ket qua" "" "CSV" 1)
fid (open fn "w")
)
(while (<= i pr)
(setq pt (vlax-curve-getPointAtParam PL i))
(setq pt1 (vlax-curve-getClosestPointTo obj pt))
(setq dis (distance pt pt1))
(setq i (1+ i))
(princ dis fid)
(princ "\n" fid)
)
(close fid)
(setvar "dimzin" olddim)
(setvar "osmode" oldos)
(command "undo" "end")
(Princ)
)
;---------------------------------
(defun HLI(enT)
(sssetfirst (ssadd enT (ssadd)) (ssadd enT (ssadd)))
)Thảo luận gốc
Lisp được chia sẻ trong chủ đề Nhờ viết Lisp xác định lý trình và khoảng cách tới tim. Xem đúng bài viết #401460 để đọc hướng dẫn và trao đổi thêm.