Jump to content

Lisp lệnh COBLK trong chủ đề “[Yêu cầu] lisp chuyển các đối tượng về 1 layer”

Bạn sửa lại như thế này, mình k test, viết tạm bạn test nhé


(defun C:CoBlk (/ i ss ls la)
(setq la (if (tblsearch "LAYER" "Block") "Block" (getvar 'clayer)))
(princ "\n Chon Blocks doi mau bylayer <select all>: ")
(setq i 0 ss (ssget '((0 . "INSERT"))))
(if (not ss)(setq ss (ssget "x" '((0 . "INSERT")))))
(command ".UNDO" "BE")
(repeat (sslength ss)
(CoBylayer (ssname ss i))
(setq i (1+ i))
)
(command ".REGEN")
(command ".UNDO" "E")
(princ)
)
(defun CoBylayer (blk / e el s)
(setq s (cdr (assoc 2 (entget blk))))
(if (not (member s ls))
(progn
(setq ls (append ls (list s)))
(setq e (cdr (assoc -2 (tblsearch "BLOCK" s))))
(while e
(setq el (entget e))
(if (= "INSERT" (cdr (assoc 0 el)))
(CoBylayer e)
)
(setq el (subst (cons 8 la) (assoc 8 el) el))
(entmod el)
(setq e (entnext e))
)
)
)
)

Cách dùng

  1. Tải tệp 206824_coblk.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 COBLK để chạy lisp.

Mã nguồn 206824_coblk.lsp

;; free lisp from cadviet.com
;;; this lisp was downloaded from https://www.cadviet.com/forum/topic/13677-y%C3%AAu-c%E1%BA%A7u-lisp-chuy%E1%BB%83n-c%C3%A1c-%C4%91%E1%BB%91i-t%C6%B0%E1%BB%A3ng-v%E1%BB%81-1-layer/

(defun  C:CoBlk (/  i ss ls la)
(setq la  (if (tblsearch "LAYER" "Block") "Block" (getvar 'clayer))) 
(princ "\n Chon Blocks doi mau bylayer <select all>: ")
(setq i 0 ss (ssget '((0 . "INSERT"))))
(if (not ss)(setq ss (ssget "x" '((0 . "INSERT")))))
(command ".UNDO" "BE")
(repeat (sslength ss)
(CoBylayer (ssname ss i))
(setq i (1+ i))
)
(command ".REGEN")
(command ".UNDO" "E")
(princ)
)
(defun  CoBylayer (blk /  e el s)
(setq s (cdr (assoc 2 (entget blk))))
(if (not (member s ls))
(progn
(setq ls (append ls (list s)))
(setq e (cdr (assoc -2 (tblsearch "BLOCK" s))))
(while e
(setq el (entget e))
(if (= "INSERT" (cdr (assoc 0 el)))
(CoBylayer e)
)
(setq el (subst (cons 8 la) (assoc 8 el) el))
(entmod el)
(setq e (entnext e))
)
)
)
)

Thảo luận gốc

Lisp được chia sẻ trong chủ đề [Yêu cầu] lisp chuyển các đối tượng về 1 layer. Xem đúng bài viết #206824 để đọc hướng dẫn và trao đổi thêm.

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