Jump to content

lisp vẽ đường bóng ( đường thể hiện dốc trên mặt bằng )

Mình đưa ra 1 ví dụ để bạn thấy việc viết lisp không đơn giản, và nếu người yêu cầu không biết mình cần gì, sẽ không bao giờ có đáp án, hoặc chí ít cũng không được như ý

(defun c:tbkd(/ eLine curve1 curve2 i j len1 len2 tmp)
(vl-load-com)
(or #dist (setq #dist 10)) ; 10 = Khoang cach mac dinh
(setq #dist (cond ((getdist (strcat "\nKhoang cach bat dau <" (vl-princ-to-string #dist) " > :")))(#dist)))
(or #inc (setq #inc 1.2)) ;
(setq #inc (cond ((getdist (strcat "\nGia so <" (vl-princ-to-string #inc) " > :")))(#inc)))
(defun eLine (p1 p2  / p2 col)(entmake  (list (cons 0 "LINE")(cons 10 p1)  (cons 11 p2)(cons 62 8)  (cons 8 "0"))))
;;Doan duoi nay khong can de y
(If
(and
(setq curve1  (car(entsel "\nPath curve 1 :")))
(setq curve2  (car(entsel "\nPath curve 2 :")))
(wcmatch (cdadr (entget curve1)) "*LINE,ARC")
(wcmatch (cdadr (entget curve2)) "*LINE,ARC")
(eLine (vlax-curve-getStartPoint curve1) (vlax-curve-getStartPoint curve2))
(setq tmp 0 i 0 len1 (vlax-curve-getDistAtParam curve1 (vlax-curve-getEndParam curve1)) len2 (vlax-curve-getDistAtParam curve2 (vlax-curve-getEndParam curve2)))
)
(while (<= (setq tmp (+ (* #dist (expt #inc (setq i (1+ i))))tmp)) len1)
 (eLine (vlax-curve-getPointAtDist curve1 tmp) (vlax-curve-getPointAtDist curve2 tmp))
)
)
)

 

 

.......................////

e thay lisp nay hay. Nhung no chi ve khi co 2 culve song song nhau , con 1 duong thang va 1 duong cheo ko ve vuong goc duoc

anh KETXU co the hieu chinh them chut nua la ok

Cách dùng

  1. Tải tệp 172133_tbkd.lsp về máy.
  2. 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ẽ.
  3. Gõ lệnh TBKD để chạy lisp.

Mã nguồn 172133_tbkd.lsp

;; free lisp from cadviet.com
;;; this lisp was downloaded from https://www.cadviet.com/forum/topic/56050-y%C3%AAu-c%E1%BA%A7u-lisp-v%E1%BA%BD-%C4%91%C6%B0%E1%BB%9Dng-b%C3%B3ng-%C4%91%C6%B0%E1%BB%9Dng-th%E1%BB%83-hi%E1%BB%87n-d%E1%BB%91c-tr%C3%AAn-m%E1%BA%B7t-b%E1%BA%B1ng/
(defun c:tbkd(/ eLine curve1 curve2 i j len1 len2 tmp)
(vl-load-com)
(or #dist (setq #dist 10)) ; 10 = Khoang cach mac dinh
(setq #dist (cond ((getdist (strcat "\nKhoang cach bat dau <" (vl-princ-to-string #dist) " > :")))(#dist)))
(or #inc (setq #inc 1.2)) ;
(setq #inc (cond ((getdist (strcat "\nGia so <" (vl-princ-to-string #inc) " > :")))(#inc)))
(defun eLine (p1 p2  / p2 col)(entmake  (list (cons 0 "LINE")(cons 10 p1)  (cons 11 p2)(cons 62 8)  (cons 8 "0"))))
;;Doan duoi nay khong can de y
(If
(and
(setq curve1  (car(entsel "\nPath curve 1 :")))
(setq curve2  (car(entsel "\nPath curve 2 :")))
(wcmatch (cdadr (entget curve1)) "*LINE,ARC")
(wcmatch (cdadr (entget curve2)) "*LINE,ARC")
(eLine (vlax-curve-getStartPoint curve1) (vlax-curve-getStartPoint curve2))
(setq tmp 0 i 0 len1 (vlax-curve-getDistAtParam curve1 (vlax-curve-getEndParam curve1)) len2 (vlax-curve-getDistAtParam curve2 (vlax-curve-getEndParam curve2)))
)
(while (<= (setq tmp (+ (* #dist (expt #inc (setq i (1+ i))))tmp)) len1)
 (eLine (vlax-curve-getPointAtDist curve1 tmp) (vlax-curve-getPointAtDist curve2 tmp))
)
)
)

Thảo luận gốc

Lisp được chia sẻ trong chủ đề [yêu cầu] lisp vẽ đường bóng ( đường thể hiện dốc trên mặt bằng ). Xem đúng bài viết #172133 để đọc hướng dẫn và trao đổi thêm.

Về Thư viện AutoLisp (trang 236)