Lisp lệnh TES trong chủ đề “Nhờ Các Bác Giúp Em Giải Quyết Bài Toán Này Với !”
Lisp trên chỉ cốt có cái nhìn "trực quan" về từng bước offset thôi. Còn muốn quét nhieu thì xài cái này.
(defun c:tes(/ D D1 D2 D3 DN DT E EG EL EL1 EL2 X Y) (defun doimn (v a b) (command "change" v "" "P" "C" a "LT" b "")) (defun laydinhr (e) (mapcar 'cdr (vl-remove-if-not '(lambda(x) (= 10 (car x))) (entget e)))) (defun line (a b m) (entmake (list '(0 . "LINE") (cons 10 a) (cons 11 b) (cons 62 m)))) (command "ucs" "w") (prompt "\nChon polyline:") (setq d (getreal "\nKich thuoc D:") d1 (getreal "\nKich thuoc D1:") d2 (getreal "\nKich thuoc D2:") d3 (getreal "\nKich thuoc D3:") ) (foreach e (vl-remove-if 'listp (mapcar 'cadr (ssnamex (ssget '((0 . "LWPOLYLINE")))))) (setq eg (laydinhr e) dt (polar (car eg) (angle (car eg) (nth 2 eg)) (* 0.5 (distance (car eg) (nth 2 eg)) )) dn (polar (car eg) (angle (nth 2 eg) (car eg)) (* 0.5 (distance (car eg) (nth 2 eg)) ))) (command "offset" (abs d) e (if (> d 0) dn dt) "") (setq el (entlast)) (doimn el 6 "continuous") (command "offset" d1 el dn "") (setq el1 (entlast)) (doimn el1 3 "continuous") (command "offset" d2 el dt "") (doimn (entlast) 3 "continuous") (command "offset" (+ d2 d3) el dt "") (setq el2 (entlast)) (doimn el2 3 "continuous") (mapcar '(lambda(x y) (line x y 3)) (laydinhr el1) (laydinhr el2)) ) (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
- Chép mã nguồn, lưu thành tệp 402889_tes.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 TES để chạy lisp.
Mã nguồn 402889_tes.lsp (trích từ bài viết gốc)
(defun c:tes(/ D D1 D2 D3 DN DT E EG EL EL1 EL2 X Y)
(defun doimn (v a b) (command "change" v "" "P" "C" a "LT" b ""))
(defun laydinhr (e) (mapcar 'cdr (vl-remove-if-not '(lambda(x) (= 10 (car x))) (entget e))))
(defun line (a b m) (entmake (list '(0 . "LINE") (cons 10 a) (cons 11 b) (cons 62 m))))
(command "ucs" "w")
(prompt "\nChon polyline:")
(setq d (getreal "\nKich thuoc D:")
d1 (getreal "\nKich thuoc D1:")
d2 (getreal "\nKich thuoc D2:")
d3 (getreal "\nKich thuoc D3:")
)
(foreach e (vl-remove-if 'listp (mapcar 'cadr (ssnamex (ssget '((0 . "LWPOLYLINE"))))))
(setq eg (laydinhr e)
dt (polar (car eg) (angle (car eg) (nth 2 eg)) (* 0.5 (distance (car eg) (nth 2 eg)) ))
dn (polar (car eg) (angle (nth 2 eg) (car eg)) (* 0.5 (distance (car eg) (nth 2 eg)) )))
(command "offset" (abs d) e (if (> d 0) dn dt) "") (setq el (entlast)) (doimn el 6 "continuous")
(command "offset" d1 el dn "") (setq el1 (entlast)) (doimn el1 3 "continuous")
(command "offset" d2 el dt "") (doimn (entlast) 3 "continuous")
(command "offset" (+ d2 d3) el dt "") (setq el2 (entlast)) (doimn el2 3 "continuous")
(mapcar '(lambda(x y) (line x y 3)) (laydinhr el1) (laydinhr el2))
)
(princ)
)Thảo luận gốc
Lisp được chia sẻ trong chủ đề Nhờ Các Bác Giúp Em Giải Quyết Bài Toán Này Với !. Xem đúng bài viết #402889 để đọc hướng dẫn và trao đổi thêm.