Lisp lệnh C%3CSPAN+STYL trong chủ đề “Viết Lisp theo yêu cầu”
Đây là lệnh CNInvis theo đúng ý bạn. Chỉ việc thêm vài dòng code so với trước. Màu đỏ là mã tôi vừa thêm.
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
- Chép mã nguồn, lưu thành tệp 9704_c%3Cspan+styl.lsp.
- 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 C%3CSPAN+STYL để chạy lisp.
Mã nguồn 9704_c%3Cspan+styl.lsp (trích từ bài viết gốc)
(defun c:C[color="#FF0000"]N[/color]InVis (/ SSet Count Elem)
(defun Dxf (Id Obj)
(cdr (assoc Id (entget Obj)))
) ;end Dxf
(cond
((setq SSet
(ssget
"X"
[color="#FF0000"](append
(list (cons -4 " (filterchondttheomau
(maucuadoituong
(car (entsel "\nHay pick vao doi tuong de chon mau: ")
)
)
)
[color="#FF0000"](list (cons -4 "NOT>")))[/color]
)
)
ssadd
(repeat (setq Count (sslength SSet))
(setq Count (1- COunt)
Elem (ssname SSet Count)
)
(if (/= 4 (logand 4 (Dxf 70 (tblobjname "layer" (Dxf 8 Elem)))))
(if (Dxf 60 Elem)
(entmod
(subst '(60 . 1) (assoc 60 (entget Elem)) (entget Elem))
)
(entmod (append (entget Elem) (list '(60 . 1))))
)
(prompt
"\nEntity on a locked layer. Cannot hide this entity. "
)
) ;end if
) ;end repeat
)
) ;end cond
(princ)
) ;end c:InVis
(defun maucuadoituong (ent)
(setq tt (entget ent)
chon (assoc 62 tt)
)
(cond
(chon (cdr chon))
(t (cdr (assoc 62 (tblsearch "layer" (cdr (assoc 8 tt))))))
)
)
(defun filterchondttheomau (mau)
(defun chonlayertheomau (mau / kq)
(setq curlay (tblnext "LAYER" t))
(while curlay
(if (= mau (cdr (assoc 62 curlay)))
(setq kq (append kq (list (cdr (assoc 2 curlay)))))
)
(setq curlay (tblnext "LAYER"))
)
kq
)
(setq filterlist
nil
taplayer (chonlayertheomau mau)
)
(foreach pp taplayer
(setq filterlist
(append filterlist
(list (cons -4 " (cons 62 256)
(cons 8 pp)
(cons -4 "AND>")
)
)
)
)
(setq filterlist
(append (list (cons -4 " filterlist
(list (cons -4 "OR>"))
)
)
)Thảo luận gốc
Lisp được chia sẻ trong chủ đề Viết Lisp theo yêu cầu. Xem đúng bài viết #9704 để đọc hướng dẫn và trao đổi thêm.