Jump to content

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



HIC. Bác Ăn gian, cái điểm N giới hạn thì từ đầu tới h chưa có mà ? hic.Bác có cách nào để nó ổn định hơn ko ? việc chọn đường biên đó rất khó và ko ổn định. mỗi lúc mỗi kiểu và các đường bóng ở gần cuối điểm N hay bị lỗi. BÁc xem hình nhé : http://www.mediafire...ysewzv3aynpzltc
Và chức năng lưu giá trị cũ..


;========code
;; free lisp from cadviet.com
;;; this lisp was downloaded from http://www.cadviet.c...opic=56050&st=0
(defun c:kbb ( / a k)
(vl-load-com)
(command "undo" "be")
(command "ucs" "w")
(command "layer" "N" "bong" "S" "bong" "color" 8 "" "")
(setq e1 (car(entsel "\n Chon goc bien duoi"))
e2 (car(entsel "\n Chon goc bien tren"))
e (car (entsel "\n Chon duong ke chuan"))
)
(or k (setq k 0.9)) ; 0.9 = he so khoang cach mac dinh
(setq k (cond ((getdist (strcat "\nhe so khoang cach <" (vl-princ-to-string k) " > :")))(k)))
(or #inc (setq #inc 1.2))
(or a (setq a 10)) ; 10 = khoang cach mac dinh
(setq a (cond ((getdist (strcat "\a0= <" (vl-princ-to-string a) " > :")))(k)))
(or #inc (setq #inc 1.2))
(setq
p (getpoint "\n Chon huong rai duong ke bong")
dis (distance p (vlax-curve-getClosestPointTo (vlax-ename->vla-object e) p T))
b 0
)
(setq la (getstring "\n Nhap ten layer: "))
(if (= (tblsearch "layer" la) nil)
(command "layer" "m" la "c" 8 "" "")
)
(setvar "clayer" la)
(command "change" e "" "p" "la" la "")
(while (and (< b dis) (> a 0.01))
(command "offset" a e p "")
(setq e (entlast)
a (* k a)
b (+ b a)
;;;;; pd (vlax-curve-getstartpoint e)
;;;;;;pc (vlax-curve-getendpoint e)
)
(if (setq p1 (acet-geom-intersectwith e e1 0))
(progn
(command "break" e (car p1) (vlax-curve-getstartpoint e))
(setq e (entlast))
)
(command "extend" e1 "" (vlax-curve-getstartpoint e) "")
)
(if (setq p2 (acet-geom-intersectwith e e2 0))
(command "break" e (car p2) (vlax-curve-getendpoint e))
(command "extend" e2 "" (vlax-curve-getendpoint e) "")
)
)
(command "undo" "e")
(princ)
)

Tệp .lsp gốc không còn trên máy chủ. Hãy chép mã nguồn bên dưới (lấy từ bài viết gốc) vào một tệp văn bản, lưu với đuôi .lsp.

Cách dùng

  1. Chép mã nguồn, lưu thành tệp 172606_kbb.lsp.
  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 KBB để chạy lisp.

Mã nguồn 172606_kbb.lsp (trích từ bài viết gốc)

;========code
;; free lisp from cadviet.com
;;; this lisp was downloaded from http://www.cadviet.c...opic=56050&st=0
(defun c:kbb ( / a k)
(vl-load-com)
(command "undo" "be")
(command "ucs" "w")
(command "layer" "N" "bong" "S" "bong" "color" 8 "" "")
(setq e1 (car(entsel "\n Chon goc bien duoi"))
e2 (car(entsel "\n Chon goc bien tren"))
e (car (entsel "\n Chon duong ke chuan"))
)
(or k (setq k 0.9)) ; 0.9 = he so khoang cach mac dinh
(setq k (cond ((getdist (strcat "\nhe so khoang cach <" (vl-princ-to-string k) " > :")))(k)))
(or #inc (setq #inc 1.2))
(or a (setq a 10)) ; 10 = khoang cach mac dinh
(setq a (cond ((getdist (strcat "\a0= <" (vl-princ-to-string a) " > :")))(k)))
(or #inc (setq #inc 1.2))
(setq
p (getpoint "\n Chon huong rai duong ke bong")
dis (distance p (vlax-curve-getClosestPointTo (vlax-ename->vla-object e) p T))
b 0
)
(setq la (getstring "\n Nhap ten layer: "))
(if (= (tblsearch "layer" la) nil)
(command "layer" "m" la "c" 8 "" "")
)
(setvar "clayer" la)
(command "change" e "" "p" "la" la "")
(while (and (< b dis) (> a 0.01))
(command "offset" a e p "")
(setq e (entlast)
a (* k a)
b (+ b a)
;;;;; pd (vlax-curve-getstartpoint e)
;;;;;;pc (vlax-curve-getendpoint e)
)
(if (setq p1 (acet-geom-intersectwith e e1 0))
(progn
(command "break" e (car p1) (vlax-curve-getstartpoint e))
(setq e (entlast))
)
(command "extend" e1 "" (vlax-curve-getstartpoint e) "")
)
(if (setq p2 (acet-geom-intersectwith e e2 0))
(command "break" e (car p2) (vlax-curve-getendpoint e))
(command "extend" e2 "" (vlax-curve-getendpoint e) "")
)
)
(command "undo" "e")
(princ)
)

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 #172606 để đọc hướng dẫn và trao đổi thêm.

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