Lisp lệnh OO trong chủ đề “Ứng dụng LISP để vẽ bản vẽ kiến trúc (phần cơ bản)”
Ờ nhỉ tí quến. Thế khi vẽ tim và tường thì làm thế nào cho nhanh. Co người thì dùng MLine, co người thì dùng Line. MLine thì không bàn, nhanh, nhưng không phải ai cũng quen. Vậy làm thế nào khi đã ve xong tim tường rồi? OFFSET ?
Bài 7: Offset line sang 2 bên
(defun c:oo(/ data_m) (defun import_data(/ i) (setq data_m (ssget)) (if (= nil distan_m) (setq distan_m 110.0)) (princ "Distance (") (princ distan_m) (princ "):") (setq i (getreal )) (if (not (= nil i)) (setq distan_m i)) ) (defun process(/ ent check) (defun p_check() (setq check 0) (if (= "LINE" (cdr (assoc 0 ent))) (setq check 1)) (princ) ) (defun p_d_offset(/ p1 p2 p3 p4) (defun makeline(/ e2 e5) ; (princ ent) ; (setq e5 nil) ; (setq e5 (cdr (assoc 5 ent))) ; (princ e5) ; (if (= nil e5) (setq e5 )) (setq la (list (cons 0 "LINE") (cons 5 (cdr (assoc 5 ent)) ) (cons 8 (cdr (assoc 8 ent)) ) (cons 10 p3) (cons 11 p4) )) ; (princ la) (entmake la) (princ) ) (setq p1 (cdr (assoc 10 ent)) p2 (cdr (assoc 11 ent)) ) (if (not (= p1 p2)) (progn (if (< (abs (- (nth 0 p1) (nth 0 p2))) 0.000001) (progn (setq p3 (list (+ (nth 0 p1) distan_m) (nth 1 p1) (nth 2 p1) ) ) (setq p4 (list (+ (nth 0 p2) distan_m) (nth 1 p2) (nth 2 p2) ) ) (makeline) (setq p3 (list (- (nth 0 p1) distan_m) (nth 1 p1) (nth 2 p1) ) ) (setq p4 (list (- (nth 0 p2) distan_m) (nth 1 p2) (nth 2 p2) ) ) (makeline) )) (if (< (abs (- (nth 1 p1) (nth 1 p2))) 0.000001) (progn (setq p3 (list (nth 0 p1) (+ (nth 1 p1) distan_m) (nth 2 p1) ) ) (setq p4 (list (nth 0 p2) (+ (nth 1 p2) distan_m) (nth 2 p2) ) ) (makeline) (setq p3 (list (nth 0 p1) (- (nth 1 p1) distan_m) (nth 2 p1) ) ) (setq p4 (list (nth 0 p2) (- (nth 1 p2) distan_m) (nth 2 p2) ) ) (makeline) )) )) (princ) ) (if (not (= nil data_m)) (progn (setq i 0) (while (< i (sslength data_m)) (progn (setq ent (entget (ssname data_m i))) (p_check) (if (= 1 check) (p_d_offset)) (setq i (+ i 1)) )) )) (princ) ) (import_data) (ai_undo_push) (process) (ai_undo_pop) (princ) )
Lênh để offset line sang 2 bên là oo.
....
Còn lắm nhưng mà ăn cơm đã..hè hè
Thông thường khi vẽ kiến trúc người ta sẽ vẽ tim đầu tiên, sau đó offset sang 2 bên hoặc dùng lệnh mline để vẽ, lisp trên của a theo e còn có hạn chế là sau khi offset sang 2 bên thì đối tượng mới trùng layer với đối tượng cũ, như vậy sẽ rất khó khăn khi tách (theo kiểu on/off layer) đối tượng ra để chỉnh sửa trong những bản vẽ phưc tạp.
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
- Chép mã nguồn, lưu thành tệp 13919_oo.lsp.
- 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 OO để chạy lisp.
Mã nguồn 13919_oo.lsp (trích từ bài viết gốc)
(defun c:oo(/ data_m)
(defun import_data(/ i)
(setq data_m (ssget))
(if (= nil distan_m) (setq distan_m 110.0))
(princ "Distance (")
(princ distan_m)
(princ "):")
(setq i (getreal ))
(if (not (= nil i)) (setq distan_m i))
)
(defun process(/ ent check)
(defun p_check()
(setq check 0)
(if (= "LINE" (cdr (assoc 0 ent))) (setq check 1))
(princ)
)
(defun p_d_offset(/ p1 p2 p3 p4)
(defun makeline(/ e2 e5)
; (princ ent)
; (setq e5 nil)
; (setq e5 (cdr (assoc 5 ent)))
; (princ e5)
; (if (= nil e5) (setq e5 ))
(setq la (list (cons 0 "LINE")
(cons 5 (cdr (assoc 5 ent)) )
(cons 8 (cdr (assoc 8 ent)) )
(cons 10 p3)
(cons 11 p4)
))
; (princ la)
(entmake la)
(princ)
)
(setq p1 (cdr (assoc 10 ent)) p2 (cdr (assoc 11 ent)) )
(if (not (= p1 p2)) (progn
(if (< (abs (- (nth 0 p1) (nth 0 p2))) 0.000001) (progn
(setq p3 (list (+ (nth 0 p1) distan_m) (nth 1 p1) (nth 2 p1) ) )
(setq p4 (list (+ (nth 0 p2) distan_m) (nth 1 p2) (nth 2 p2) ) )
(makeline)
(setq p3 (list (- (nth 0 p1) distan_m) (nth 1 p1) (nth 2 p1) ) )
(setq p4 (list (- (nth 0 p2) distan_m) (nth 1 p2) (nth 2 p2) ) )
(makeline)
))
(if (< (abs (- (nth 1 p1) (nth 1 p2))) 0.000001) (progn
(setq p3 (list (nth 0 p1) (+ (nth 1 p1) distan_m) (nth 2 p1) ) )
(setq p4 (list (nth 0 p2) (+ (nth 1 p2) distan_m) (nth 2 p2) ) )
(makeline)
(setq p3 (list (nth 0 p1) (- (nth 1 p1) distan_m) (nth 2 p1) ) )
(setq p4 (list (nth 0 p2) (- (nth 1 p2) distan_m) (nth 2 p2) ) )
(makeline)
))
))
(princ)
)
(if (not (= nil data_m)) (progn
(setq i 0)
(while (< i (sslength data_m)) (progn
(setq ent (entget (ssname data_m i)))
(p_check)
(if (= 1 check) (p_d_offset))
(setq i (+ i 1))
))
))
(princ)
)
(import_data)
(ai_undo_push)
(process)
(ai_undo_pop)
(princ)
)Thảo luận gốc
Lisp được chia sẻ trong chủ đề Ứng dụng LISP để vẽ bản vẽ kiến trúc (phần cơ bản). Xem đúng bài viết #13919 để đọc hướng dẫn và trao đổi thêm.