Lisp lệnh DOPL trong chủ đề “Lisp dim khoảng cách liên tiếp trên Polyline - Pline”
Trường hợp này không dùng hàm command được.
Bạn test thử code nhé :
(defun c:dopl() (setq acadObj (vlax-get-acad-object)) (setq doc (vla-get-ActiveDocument acadObj)) (setq modelSpace (vla-get-ModelSpace doc)) (setq i 0) (if (and (setq e (car(entsel "\n Chon Pline : "))) (setq ddat (getpoint (vlax-curve-getstartpoint e) "\nDist (Pick diem) :"))) (progn (setq obj (vlax-ename->vla-object e)) (setq dis (distance ddat (vlax-curve-getclosestpointto e ddat))) (Repeat (fix (vlax-curve-getEndParam e)) (if (= 0 (vla-GetBulge obj i)) (vla-AddDimAligned modelSpace (vlax-3d-point (vlax-curve-getpointatparam e i)) (vlax-3d-point (vlax-curve-getpointatparam e (1+ i)) ) (vlax-3d-point (polar (vlax-curve-getpointatparam e (+ i 0.5)) (- (angle '(0 0 0) (vlax-curve-getFirstDeriv e (+ i 0.5))) (/ pi 2.0)) dis) ) ) (vla-AddDimArc modelSpace (vlax-3d-point (mapcar '+ (vlax-curve-getpointatparam e (+ i 0.5)) (vlax-curve-getSecondDeriv e (+ i 0.5)))) (vlax-3d-point (vlax-curve-getpointatparam e i)) (vlax-3d-point (vlax-curve-getpointatparam e (1+ i)) ) (vlax-3d-point (polar (vlax-curve-getpointatparam e (+ i 0.5)) (- (angle '(0 0 0) (vlax-curve-getFirstDeriv e (+ i 0.5))) (/ pi 2.0)) dis) ) ) );if (setq i (1+ i)) );Repeat );progn );if )
Hề hề hề,
Bác Tue_NV xem xét giùm vì sao khi tải lisp trên về thì không thể load lisp được. Nhưng khi mình copy code và đổi tên file cho nó thì lại load bình thường.
Khi load được lisp và xài thử thì lại bị thông báo rằng không có lệnh (vla-adddimarc ......... ) bác ạ.
- Tải lisp
- 361224_dopl.lsp
Cách dùng
- Tải tệp 361224_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 361224_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/
(defun c:dopl()
(setq acadObj (vlax-get-acad-object))
(setq doc (vla-get-ActiveDocument acadObj))
(setq modelSpace (vla-get-ModelSpace doc))
(setq i 0)
(if (and (setq e (car(entsel "\n Chon Pline : "))) (setq ddat (getpoint (vlax-curve-getstartpoint e) "\nDist (Pick diem) :")))
(progn
(setq obj (vlax-ename->vla-object e))
(setq dis (distance ddat (vlax-curve-getclosestpointto e ddat)))
(Repeat (fix (vlax-curve-getEndParam e))
(if (= 0 (vla-GetBulge obj i))
(vla-AddDimAligned modelSpace
(vlax-3d-point (vlax-curve-getpointatparam e i)) (vlax-3d-point (vlax-curve-getpointatparam e (1+ i)) )
(vlax-3d-point (polar (vlax-curve-getpointatparam e (+ i 0.5))
(- (angle '(0 0 0) (vlax-curve-getFirstDeriv e (+ i 0.5))) (/ pi 2.0)) dis)
)
)
(vla-AddDimArc modelSpace (vlax-3d-point (mapcar '+ (vlax-curve-getpointatparam e (+ i 0.5)) (vlax-curve-getSecondDeriv e (+ i 0.5))))
(vlax-3d-point (vlax-curve-getpointatparam e i)) (vlax-3d-point (vlax-curve-getpointatparam e (1+ i)) )
(vlax-3d-point (polar (vlax-curve-getpointatparam e (+ i 0.5))
(- (angle '(0 0 0) (vlax-curve-getFirstDeriv e (+ i 0.5))) (/ pi 2.0)) dis)
)
)
);if
(setq i (1+ i))
);Repeat
);progn
);if
)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 #361224 để đọc hướng dẫn và trao đổi thêm.