Jump to content

Lisp lệnh CTHUA trong chủ đề “Viết lisp theo yêu cầu [phần 2]”


Bạn yêu cầu gì mà khoai thế. Mình viết cho bạn được thế này bạn test thử và cho ý kiến để hoàn thiện

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

  1. Chép mã nguồn, lưu thành tệp 119813_cthua.lsp.
  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 CTHUA để chạy lisp.

Mã nguồn 119813_cthua.lsp (trích từ bài viết gốc)

(defun c:cthua ()
(vl-load-com)
 (setq oldos (getvar "osmode"))
 (setvar "osmode" 0)
 (while (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))
   (acet-ss-zoom-extents (acet-list-to-ss (list el2)))
   (setq lsp (acet-geom-vertex-list el2))
   (setq ss (ssget "cp" lsp))
   (setq ss (ssdel el1 ss))
   (setq ss (ssdel el2 ss))
   (command "zoom" "p")
   (command "copy" ss "" p (setq pm (getpoint "\nPick vao vi tri can chen")) "")
   (command "move" el1 el2 "" p pm)
   (command "offset" 1 el2 p "")
   (setq el3 (entlast))
   (setq lsf (acet-geom-vertex-list el3))
   (setq i 0)
   (command "trim" el2 "" "f")
   (repeat (length lsf)
     (command (nth i lsf))
     (setq i (1+ i))
     )
   (command "" "")
   (entdel el1)
   (entdel el2)
   (entdel el3)
   (setq dk (getstring "\nTrich thua da hoan thanh. ban co muon tiep tuc khong: [Co/Khong]: < Co >: "))
   (if (or (= (strcase dk) "C") (= dk "")) (setq p T) (setq p nil))
   )
 (setvar "osmode" oldos)
 )

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 #119813 để đọc hướng dẫn và trao đổi thêm.

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