Jump to content

nhờ làm lisp vẽ tường....

mình làm bên thiết kế vì vẽ tường toàn dùng lệnh Xline và lệnh oset đối tượng

mình có thể nói rõ thế này

ví dụ mình có đường tim,có tường dầy 200 thay vì oset 2 lần 100 thì mình chỉ cần oset 1 lần sang 2 bên cách tim 100 (nếu mà nó thay thế được được Xline thì càng tốt) và có thể oset theo trục chéo .......

lisp mình tìm được này chỉ oset được đường line mình vẽ chứ kg làm được đường xline và kg oset được theo trục chéo,chỉ theo mỗi trục x và y.... >_<


;;OFFSET VE 2 BEN CUA 1 DOI TUONG ( )
(defun c:oo(/ data_m)
(defun import_data(/ i)
(setq data_m (ssget))
(if (= nil distan_m) (setq distan_m 110.0))
(princ "Khoang cach line cach deu sang hai ben (")
(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)
)
(SETVAR "osmode" 16383)
(setvar "pickbox" 6)
(setvar "aperture" 6)
(setvar "orthomode" 1)



nhờ các bạn sửa lại dùm! để có thể oset theo trục chéo và dùng đc xline thay cho đường line mình vẽ

thank các bạn rất nhiều :D

Cách dùng

  1. Tải tệp 183765_oo.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 OO để chạy lisp.

Mã nguồn 183765_oo.lsp

;; free lisp from cadviet.com
;;; this lisp was downloaded from https://www.cadviet.com/forum/topic/60339-y%C3%AAu-c%E1%BA%A7u-nh%E1%BB%9D-l%C3%A0m-lisp-v%E1%BA%BD-t%C6%B0%E1%BB%9Dng/
;;OFFSET VE 2 BEN CUA 1 DOI TUONG  (  )
(defun c:oo(/ data_m)
(defun import_data(/ i)
(setq data_m (ssget))
(if (= nil distan_m) (setq distan_m 110.0))
(princ "Khoang cach line cach deu sang hai ben (")
(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)
)
(SETVAR "osmode" 16383)
(setvar "pickbox" 6)
(setvar "aperture" 6)
(setvar "orthomode" 1)  

Thảo luận gốc

Lisp được chia sẻ trong chủ đề [Yêu cầu] nhờ làm lisp vẽ tường..... Xem đúng bài viết #183765 để đọc hướng dẫn và trao đổi thêm.

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