Lisp lệnh CBL trong chủ đề “Nhờ viết lisp đổi màu về bylayer”
Chuyển về Bylayer các đối tượng chọn theo ý tưởng của bạn thì :;; free lisp from cadviet.com @ssg ;;;------------------------------------------------------------------------------- (defun remc(s / sn i OK sc ch) ;;;Remove color code (setq sn "" i 1 OK T) (repeat (strlen s) (setq sc (substr s i 2) ch (substr s i 1) ) (if (= sc "\\C") (setq OK nil)) (if OK (setq sn (strcat sn ch)) (if (= ch ";") (setq OK T)) ) (setq i (1+ i)) ) sn ) ;;;------------------------------------------------------------------------------- (defun C:CBL(/ ss e d old new) ;;;Reset all objects ByLayer (setq ss (ssget "X" '((0 . "MTEXT")))) (while (setq e (ssname ss 0)) (setq d (entget e) old (assoc 1 d) new (cons 1 (remc (cdr old))) d (subst new old d) ) (entmod d) (ssdel e ss) ) (command "change" (ssget "X") "" "p" "C" "bylayer" "LT" "bylayer" "LW" "bylayer" "") (princ) ) ;;;-------------------------------------------------------------------------------
- Tải lisp
- 125888_cbl.lsp
Cách dùng
- Tải tệp 125888_cbl.lsp về máy.
- 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 CBL để chạy lisp.
Mã nguồn 125888_cbl.lsp
;; free lisp from cadviet.com
;;; this lisp was downloaded from https://www.cadviet.com/forum/topic/31768-nh%E1%BB%9D-vi%E1%BA%BFt-lisp-%C4%91%E1%BB%95i-m%C3%A0u-v%E1%BB%81-bylayer/?tab=comments#comment-125869
;; free lisp from cadviet.com @ssg
;;;-------------------------------------------------------------------------------
(defun remc(s / sn i OK sc ch) ;;;Remove color code
(setq sn "" i 1 OK T)
(repeat (strlen s)
(setq
sc (substr s i 2)
ch (substr s i 1)
)
(if (= sc "\\C") (setq OK nil))
(if OK
(setq sn (strcat sn ch))
(if (= ch ";") (setq OK T))
)
(setq i (1+ i))
)
sn
)
;;;-------------------------------------------------------------------------------
(defun C:CBL(/ ss e d old new) ;;;Reset all objects ByLayer
(setq ss (ssget "X" '((0 . "MTEXT"))))
(while (setq e (ssname ss 0))
(setq
d (entget e)
old (assoc 1 d)
new (cons 1 (remc (cdr old)))
d (subst new old d)
)
(entmod d)
(ssdel e ss)
)
(command "change" (ssget "X") "" "p" "C" "bylayer" "LT" "bylayer" "LW" "bylayer" "")
(princ)
)
;;;-------------------------------------------------------------------------------
Thảo luận gốc
Lisp được chia sẻ trong chủ đề Nhờ viết lisp đổi màu về bylayer. Xem đúng bài viết #125888 để đọc hướng dẫn và trao đổi thêm.