Jump to content

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


Bạn thử cái này nhé. Vùng cắt là hình chữ nhật khi nhập khoảng cách thì hình chữ nhật sẽ rộng thêm ra còn mạch định là hình chữ nhật bao ngoài thửa đất (khi khoảng cách bằng 0). Làm như vậy để trách trưởng hợp khi bạn nhập kích thước hình chữ nhật nhỏ hơn thửa đất thì lisp chạy bị lỗi.

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 121440_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 121440_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 "")
   (setq el1 (entlast))
   (setq of (getreal "\nNhap khoang cach muon lay ra xung quanh: "))
   (setq recp (acet-ent-geomextents el1))
   (setq rec1 (car recp) rec2 (cadr recp))
   (command "rectang" rec1 rec2)
   (setq elrec (entlast))
   (setq ranp (car (acet-geom-vertex-list elrec)))
   (setq pout (polar p (angle p ranp) (+ (distance p ranp) of)))
   (command "offset" of elrec 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))
   (setq ss (ssdel elrec 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 elrec "" 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 elrec)
   (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 #121440 để đọc hướng dẫn và trao đổi thêm.

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