Đo khoảng cách hai điểm và ghi kết quả ra nơi minh chọn
- ah vậy ý bạn đó là lấy khoảng cách 2 điểm bất kỳ thuộc đường đã chọn ^^, theo gợi ý anh Ket nhoc viết lại thế này xem bạn đó vừa ý chưa hì :)
;=======================
(defun _d2p(e p1 p2) ;Getdist along curve by : Ename P1 P2
(abs (apply '- (mapcar '(lambda(x)(vlax-curve-getDistAtPoint e (trans (vlax-curve-getclosestpointto e x) 1 0))) (list p1 p2))))
)
;====================================
(defun C:TL3(/ ss L te p1 p2 textmau P enty old)
(setq old (getvar 'osmode))
(setvar 'osmode 545)
(prompt "chon doi tuong")
(while (and
(setq ss (ssget "+.:E:S" (list (cons 0 "*LINE,ARC,CIRCLE,ELLIPSE,SPLINE"))))
(setq p1 (getpoint "\n Chon diem thu nhat :"))
(setq p2 (getpoint p1 "\n Chon diem thu hai :"))
)
(setq enty (ssname ss 0))
(setq L (_d2p enty p1 p2))
(setq p (getpoint "\nPick diem chen hoac enter bo qua de chon Text :"))
(cond ((/= p nil)
(if (not textmau) (setq textmau (car(entsel "\nChon Text mau:"))))
(entmake (list (cons 0 "TEXT") (cons 1 (rtos L 2 2)) (assoc 40 (entget textmau))
(cons 10 p) (cons 11 p) (assoc 7 (entget textmau))
))
)
((= p nil)
(setq te (entget (car (entsel "\n Chon Text de gan ket qua :")))
te (subst (cons 1 (rtos L 2 2)) (assoc 1 te) te))
(entmod te)
)
)
(princ "\n")
(prompt "chon doi tuong")
)
(setvar 'osmode old)
(princ)
)
- Tải lisp
- 320178_tl3.lsp
Cách dùng
- Tải tệp 320178_tl3.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 TL3 để chạy lisp.
Mã nguồn 320178_tl3.lsp
;; free lisp from cadviet.com
;;; this lisp was downloaded from https://www.cadviet.com/forum/topic/61450-nh%E1%BB%9D-ch%E1%BB%89nh-s%E1%BB%ADa-%C4%91o-kho%E1%BA%A3ng-c%C3%A1ch-hai-%C4%91i%E1%BB%83m-v%C3%A0-ghi-k%E1%BA%BFt-qu%E1%BA%A3-ra-n%C6%A1i-minh-ch%E1%BB%8Dn/
;=======================
(defun _d2p(e p1 p2) ;Getdist along curve by : Ename P1 P2
(abs (apply '- (mapcar '(lambda(x)(vlax-curve-getDistAtPoint e (trans (vlax-curve-getclosestpointto e x) 1 0))) (list p1 p2))))
)
;====================================
(defun C:TL3(/ ss L te p1 p2 textmau P enty old)
(setq old (getvar 'osmode))
(setvar 'osmode 545)
(prompt "chon doi tuong")
(while (and
(setq ss (ssget "+.:E:S" (list (cons 0 "*LINE,ARC,CIRCLE,ELLIPSE,SPLINE"))))
(setq p1 (getpoint "\n Chon diem thu nhat :"))
(setq p2 (getpoint p1 "\n Chon diem thu hai :"))
)
(setq enty (ssname ss 0))
(setq L (_d2p enty p1 p2))
(setq p (getpoint "\nPick diem chen hoac enter bo qua de chon Text :"))
(cond ((/= p nil)
(if (not textmau) (setq textmau (car(entsel "\nChon Text mau:"))))
(entmake (list (cons 0 "TEXT") (cons 1 (rtos L 2 2)) (assoc 40 (entget textmau))
(cons 10 p) (cons 11 p) (assoc 7 (entget textmau))
))
)
((= p nil)
(setq te (entget (car (entsel "\n Chon Text de gan ket qua :")))
te (subst (cons 1 (rtos L 2 2)) (assoc 1 te) te))
(entmod te)
)
)
(princ "\n")
(prompt "chon doi tuong")
)
(setvar 'osmode old)
(princ)
)Thảo luận gốc
Lisp được chia sẻ trong chủ đề [Nhờ Chỉnh Sửa] Đo khoảng cách hai điểm và ghi kết quả ra nơi minh chọn. Xem đúng bài viết #320178 để đọc hướng dẫn và trao đổi thêm.