Jump to content

Lisp lệnh INSBLK trong chủ đề “thay thế các đường tròn bằng block”


Lisp thay thế các đường tròn có sẵn bằng Block.
Tương tự các lisp trên, có bổ sung hộp thoại chọn Block : với tùy chọn xóa Circle.

https://www.cadviet.com/upfiles/3/insblk.jpg

Cách dùng

  1. Tải tệp 109913_insblk.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 INSBLK để chạy lisp.

Mã nguồn 109913_insblk.lsp

;; free lisp from cadviet.com
;;; this lisp was downloaded from https://www.cadviet.com/forum/topic/25215-thay-th%E1%BA%BF-c%C3%A1c-%C4%91%C6%B0%E1%BB%9Dng-tr%C3%B2n-b%E1%BA%B1ng-block/
(defun c:InsBlk (/ blk_list BlkNam dcflag ss)
;|  By : Gia Bach, gia_bach @  www.CadViet.com             |;  
 (defun GetBlkLst(/ name tbl tbl_lst)
   (setq tbl (tblnext "block" T))
   (while tbl
     (if (/= (substr (setq name (cdr (assoc 2 tbl))) 1 1) "*")
(setq tbl_lst (cons name tbl_lst)))
     (setq tbl (tblnext "block"))  )
   (vl-sort tbl_lst '<))
 (defun delCir_set ()
   (if (= "1" (get_tile "delCir")) (setq delCir 1)(setq delCir 0)) ) 
 (defun Dialog_Show (lst / dxfdcl fn dxf_id)
   (setq dxfdcl (vl-filename-mktemp "InsBlk.tmp")
  fn (open dxfdcl "w"))
   (foreach item (list
	    "InsBlk : dialog {label=\"Insert Block\";"
	    "       : popup_list  {key =\"BlkLst\"; label=\"Select Block\"; width = 15; height = 15;}"
	    "       : toggle   {key =\"delCir\"; label=\"Delete Circle\"; value=\"0\";}"
	    "         ok_cancel; }")
     (princ item fn) )
   (close fn)
   (setq dxf_id (load_dialog dxfdcl))
   (if (not (if dxfXY (new_dialog "InsBlk" dxf_id "" dxfXY)(new_dialog "InsBlk" dxf_id)))
     (progn (prompt "\nKhong thay hop thoai.")(exit)))
   (start_list "BlkLst" 3) (mapcar 'add_list lst) (end_list)
   (action_tile "BlkLst" "(setq BlkNam (nth (atoi $value) lst))")
   (action_tile "delCir" "(delCir_set)")
   (action_tile "accept" "(setq dxfXY (done_dialog 1))")
   (setq dcflag (start_dialog))
   (unload_dialog dxf_id)
   (vl-file-delete dxfdcl)
   (princ))
;------- Main program ------------
 (setq delCir 0
blk_list (GetBlkLst)
BlkNam (nth 0 blk_list))
 (Dialog_Show blk_list)
 (if (= 1 dcflag)
   (if (setq ss (ssget '((0 . "CIRCLE"))));(8 . "HK")
     ((lambda (i / ent pt)
 (while (setq ent (ssname ss (setq i (1+ i))))
   (setq pt (cdr (assoc 10 (entget ent))))
   (entmake (list (cons 0 "INSERT")(cons 2 BlkNam) (cons 10 pt)))
   (entmake (list (cons 0 "SEQEND")))
   (if (= delCir 1) (entdel ent)))) -1)
   (alert "Nothing's Selected")))
 (princ)  )

Thảo luận gốc

Lisp được chia sẻ trong chủ đề thay thế các đường tròn bằng block. Xem đúng bài viết #109913 để đọc hướng dẫn và trao đổi thêm.

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