Nhờ viết lisp vẽ đường thẳng vuông góc với Pline
Của bạn đây.
(defun c:test(/ cd pl obj dd dait cl sl n os ki ) (defun ad(v p1 p2 / a1) (abs (- (vlax-curve-getDistAtPoint (setq a1 (vlax-ename->vla-object v)) (vlax-curve-getClosestPointTo a1 p2)) (vlax-curve-getDistAtPoint a1 (vlax-curve-getClosestPointTo a1 p1))))) (defun getp(v dis) (vlax-curve-getPointAtDist (vlax-ename->vla-object v) dis)) (defun thgoc (ent pt / param obj) (if (setq param (vlax-curve-getParamAtPoint (setq obj (vlax-ename->vla-object ent)) pt)) (- (angle '(0 0 0) (vlax-curve-getFirstDeriv obj param)) (/ pi 2)) nil)) (defun daitc(v / obj) (vlax-curve-getDistAtParam (setq obj (vlax-ename->vla-object v)) (vlax-curve-getEndParam obj))) ;;; (setq pl (car (entsel "\nChon Polyline:")) li (car (entsel "\nChon duong thang vuong goc voi Polyline:")) dail (daitc li) dd (getpoint "\nDiem cuoi cua Polyline:") cd (getreal "\nNhap buoc de rai:") obj (vlax-ename->vla-object pl) dg (vlax-curve-getClosestPointTo obj (acet-dxf 10 (entget li))) sl (getint "\nSo luong coc rai") ct (vlax-curve-getDistAtPoint obj dg) n 0 os (getvar "OSMODE")) (if (< (distance dd (vlax-curve-getStartPoint obj)) (distance dd (vlax-curve-getEndPoint obj))) (setq ki nil) (setq ki t)) (setvar "OSMODE" 0) (repeat sl (command "line" (setq dg1 (if ki (getp pl (+ ct (* (setq n (1+ n)) cd))) (getp pl (- ct (* (setq n (1+ n)) cd))))) (polar dg1 (thgoc pl dg1) dail) "")) (setvar "OSMODE" os) (princ) )
Bác ơi lips rất hay nhưng bác giúp em chỉnh sửa lại 1 tí được ko ạ:
- bác cho thêm lựa chọn chọn 1lúc nhiều đối tượng chứ ko chỉ 1 đối tượng
- đến chỗ lựa chọn theo em nghĩ nếu đã có bước rải thì thôi lựa chọn số cọc cần rải. Tuy nhiên em thấy lips bắt nhập cả nếu ko nhập sẽ bị lỗi. Chỗ này bác cho độc lập thì hay vẫn sẽ hỏi như vậy nhưng nếu muốn nhập số cọc cần rải thì ko nhập vào bước cần rải.
Thanks bác nhiều ạ.
- Tải lisp
- 297338_test.lsp
Cách dùng
- Tải tệp 297338_test.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 TEST để chạy lisp.
Mã nguồn 297338_test.lsp
;; free lisp from cadviet.com
;;; this lisp was downloaded from https://www.cadviet.com/forum/topic/95700-y%C3%AAu-c%E1%BA%A7u-nh%E1%BB%9D-vi%E1%BA%BFt-lisp-v%E1%BA%BD-%C4%91%C6%B0%E1%BB%9Dng-th%E1%BA%B3ng-vu%C3%B4ng-g%C3%B3c-v%E1%BB%9Bi-pline/
(defun c:test(/ cd pl obj dd dait cl sl n os ki )
(defun ad(v p1 p2 / a1)
(abs (- (vlax-curve-getDistAtPoint (setq a1 (vlax-ename->vla-object v)) (vlax-curve-getClosestPointTo a1 p2))
(vlax-curve-getDistAtPoint a1 (vlax-curve-getClosestPointTo a1 p1)))))
(defun getp(v dis)
(vlax-curve-getPointAtDist (vlax-ename->vla-object v) dis))
(defun thgoc (ent pt / param obj)
(if (setq param (vlax-curve-getParamAtPoint (setq obj (vlax-ename->vla-object ent)) pt))
(- (angle '(0 0 0) (vlax-curve-getFirstDeriv obj param)) (/ pi 2))
nil))
(defun daitc(v / obj)
(vlax-curve-getDistAtParam (setq obj (vlax-ename->vla-object v)) (vlax-curve-getEndParam obj)))
;;;
(setq pl (car (entsel "\nChon Polyline:"))
li (car (entsel "\nChon duong thang vuong goc voi Polyline:"))
dail (daitc li)
dd (getpoint "\nDiem cuoi cua Polyline:")
cd (getreal "\nNhap buoc de rai:")
obj (vlax-ename->vla-object pl)
dg (vlax-curve-getClosestPointTo obj (acet-dxf 10 (entget li)))
sl (getint "\nSo luong coc rai")
ct (vlax-curve-getDistAtPoint obj dg)
n 0
os (getvar "OSMODE"))
(if (< (distance dd (vlax-curve-getStartPoint obj)) (distance dd (vlax-curve-getEndPoint obj)))
(setq ki nil) (setq ki t))
(setvar "OSMODE" 0)
(repeat sl
(command "line"
(setq dg1 (if ki (getp pl (+ ct (* (setq n (1+ n)) cd)))
(getp pl (- ct (* (setq n (1+ n)) cd)))))
(polar dg1 (thgoc pl dg1) dail) ""))
(setvar "OSMODE" os)
(princ)
)Thảo luận gốc
Lisp được chia sẻ trong chủ đề [ Yêu cầu ] Nhờ viết lisp vẽ đường thẳng vuông góc với Pline. Xem đúng bài viết #297338 để đọc hướng dẫn và trao đổi thêm.