Lisp đo khoảng cách các điểm trên polyline
Quick code:
(defun c:dopl() (setq i 0) (if (setq e (car(entsel "\n Chon Pline : "))) (progn (setq obj (vlax-ename->vla-object e)) (if (= 0 (vla-GetBulge obj i)) (command "._dimlinear" "_non" (vlax-curve-getstartpoint e) "_non" (vlax-curve-getpointatparam e (1+ i)) "_non" pause) (command "._dimarc" (vlax-curve-getpointatparam e (+ i 0.5)) "_non" pause) ) (setq i (1+ i) ddat (cdr(assoc 10 (entget (entlast)))) dis (distance ddat (vlax-curve-getclosestpointto e ddat))) (Repeat (1- (fix (vlax-curve-getEndParam e))) (if (= 0 (vla-GetBulge obj i)) (command "._dimlinear" "_non" (vlax-curve-getpointatparam e i) "_non" (vlax-curve-getpointatparam e (1+ i)) "_non" (polar (vlax-curve-getpointatparam e (+ i 0.5)) (- (angle '(0 0 0) (vlax-curve-getFirstDeriv e (+ i 0.5))) (/ pi 2.0)) dis)) (command "._dimarc" (vlax-curve-getpointatparam e (+ i 0.5)) "_non" (polar (vlax-curve-getpointatparam e (+ i 0.5)) (- (angle '(0 0 0) (vlax-curve-getFirstDeriv e (+ i 0.5))) (/ pi 2.0)) dis)) ) (setq i (1+ i) ddat (cdr(assoc 10 (entget (entlast)))) ) ) ) ) )
Các ơn Bác đã quan tâm đã text nhưng còn 1 vướng mắc có cái đo được có cái đo không được. Qua những lần text phát hiện điểm đặt của dim ở gần polyline thì được (điểm đặt này còn phụ thuộc vào chiều dài đoạn đo)
- Tải lisp
- 360659_dopl.lsp
Cách dùng
- Tải tệp 360659_dopl.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 DOPL để chạy lisp.
Mã nguồn 360659_dopl.lsp
;; free lisp from cadviet.com
;;; this lisp was downloaded from https://www.cadviet.com/forum/topic/138433-lisp-dim-kho%E1%BA%A3ng-c%C3%A1ch-li%C3%AAn-ti%E1%BA%BFp-tr%C3%AAn-polyline-pline/?tab=comments
(defun c:dopl()
(setq i 0)
(if (setq e (car(entsel "\n Chon Pline : ")))
(progn
(setq obj (vlax-ename->vla-object e))
(if (= 0 (vla-GetBulge obj i))
(command "._dimlinear" "_non" (vlax-curve-getstartpoint e) "_non" (vlax-curve-getpointatparam e (1+ i))
"_non" pause)
(command "._dimarc" (vlax-curve-getpointatparam e (+ i 0.5)) "_non" pause)
)
(setq i (1+ i) ddat (cdr(assoc 10 (entget (entlast)))) dis (distance ddat (vlax-curve-getclosestpointto e ddat)))
(Repeat (1- (fix (vlax-curve-getEndParam e)))
(if (= 0 (vla-GetBulge obj i))
(command "._dimlinear" "_non" (vlax-curve-getpointatparam e i) "_non" (vlax-curve-getpointatparam e (1+ i))
"_non" (polar (vlax-curve-getpointatparam e (+ i 0.5)) (- (angle '(0 0 0) (vlax-curve-getFirstDeriv e (+ i 0.5))) (/ pi 2.0)) dis))
(command "._dimarc" (vlax-curve-getpointatparam e (+ i 0.5))
"_non" (polar (vlax-curve-getpointatparam e (+ i 0.5)) (- (angle '(0 0 0) (vlax-curve-getFirstDeriv e (+ i 0.5))) (/ pi 2.0)) dis))
)
(setq i (1+ i) ddat (cdr(assoc 10 (entget (entlast)))) )
)
)
)
)Thảo luận gốc
Lisp được chia sẻ trong chủ đề Lisp dim khoảng cách liên tiếp trên Polyline - Pline. Xem đúng bài viết #360659 để đọc hướng dẫn và trao đổi thêm.