Lisp lệnh CTHUA trong chủ đề “Viết lisp theo yêu cầu [phần 2]”
Bạn dùng thử cái này. Do không tìm ra thuật toán để lọc các text không liên quan nên bạn chịu khó xoá bớt bằng tay. Anh em trên diễn đàn có ý nào hay thì sửa giúp bạn lacvanhoa nhé.
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 119850_cthua.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 CTHUA để chạy lisp.
Mã nguồn 119850_cthua.lsp (trích từ bài viết gốc)
(defun c:cthua ()
(vl-load-com)
(setq oldos (getvar "osmode"))
(setvar "osmode" 0)
(setq p T)
(while p
(setq p (getpoint "\nPick vao vi tri thua muon trich do: "))
(command "boundary" p "")
(command "area" "o" (setq el1 (entlast)))
(setq of (/ (sqrt (getvar "area")) 6))
(setq ranp (car (acet-geom-vertex-list el1)))
(setq pout (polar p (angle p ranp) (+ (distance p ranp) of)))
(command "offset" of el1 pout "")
(setq el2 (entlast))
(command "zoom" "e")
(setq lsp (acet-geom-vertex-list el2))
(setq ss (ssget "cp" lsp '((0 . "LINE,LWPOLYLINE"))))
(setq ss (ssdel el1 ss))
(setq ss (ssdel el2 ss))
(command "copy" ss "" p (setq pm (getpoint "\nPick vao vi tri can chen")) "")
(setq sstext (laytext el1 (* of 6) pm))
(command "copy" sstext "" p pm "")
(command "move" el1 el2 "" p pm)
(command "offset" 1 el2 p "")
(setq el3 (entlast))
(setq lsf (acet-geom-vertex-list el3))
(setq i 0)
(repeat 2
(command "trim" el2 "" "f")
(repeat (length lsf)
(command (nth i lsf))
(setq i (1+ i))
)
(command "" "")
)
(entdel el1)
(entdel el2)
(entdel el3)
(command "zoom" "p")
(setq dk (getstring "\nTrich thua da hoan thanh. ban co muon tiep tuc khong: : [Co]: "))
(if (or (= (strcase dk) "C") (= dk "")) (setq p T))
(if (= (strcase dk) "K") (setq p nil))
)
(setvar "osmode" oldos)
)
(defun laytext ( plk kc po / elt lstt)
(command "offset" kc plk po "")
(setq elt (entlast))
(setq lstt (acet-geom-vertex-list elt))
(setq sst (ssget "wp" lstt '((0 . "TEXT"))))
(command "undo" 1)
sst
)Thảo luận gốc
Lisp được chia sẻ trong chủ đề Viết lisp theo yêu cầu [phần 2]. Xem đúng bài viết #119850 để đọc hướng dẫn và trao đổi thêm.