Jump to content

Lisp lệnh OO trong chủ đề “Lệnh offset đặc biệt”

thử cái này đi. chắc bạn sẽ hài lòng...

(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)
)

 

chỉ áp dụng được đường thẳng không áp cho đường xiên được thật là chưa vui hết đâu

Cách dùng

  1. Tải tệp 79324_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 79324_oo.lsp

;; free lisp from cadviet.com
;;; this lisp was downloaded from https://www.cadviet.com/forum/topic/1642-l%E1%BB%87nh-offset-%C4%91%E1%BA%B7c-bi%E1%BB%87t/
(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ủ đề Lệnh offset đặc biệt. Xem đúng bài viết #79324 để đọc hướng dẫn và trao đổi thêm.

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