Jump to content

Ẩn hiện đối tượng theo màu

Chui vào bên trong xem tốc độ có ổn hơn không. Mình sử dụng VL

 

(defun c:cisov(/ _table _vlacol lays adoc col)
	(vl-load-com) 
	(defun _table (s / d r)
		(while (setq d (tblnext s (null d)))
			(setq r (append  (list (cons (cdr (assoc 2 d)) (cdr (assoc 62 d)))) r))
		)	
	)
	(defun _vlacol(obj lays / col)(if (/= (setq col (vla-get-color obj)) 256) col (cdr (assoc (vla-get-layer obj) lays))))
	(setq lays (table "LAYER"))
	(setq adoc (vla-get-activedocument (vlax-get-acad-object)))
	(setq col (get_vlacol (vlax-ename->vla-object (car(entsel))) lays)) 
	(vla-startundomark adoc)
	(vlax-for block (vla-get-blocks adoc)     
		  (vlax-for   ent block 
			(if (/= (get_vlacol ent lays) col) (vla-put-visible ent 0))
		)
	)
	(vla-endundomark adoc)
)

(defun c:cunisov(/ adoc)
	(vl-load-com) 	
	(setq adoc (vla-get-activedocument (vlax-get-acad-object)))	
	(vlax-for block (vla-get-blocks adoc)     
		  (vlax-for   ent block 
			(vla-put-visible ent 1)
		)
	)
)

Cách dùng

  1. Tải tệp 268211_cisov_cunisov.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 CISOV CUNISOV để chạy lisp.

Mã nguồn 268211_cisov_cunisov.lsp

;; free lisp from cadviet.com
;;; this lisp was downloaded from https://www.cadviet.com/forum/topic/88632-y%C3%AAu-c%E1%BA%A7u-%E1%BA%A9n-hi%E1%BB%87n-%C4%91%E1%BB%91i-t%C6%B0%E1%BB%A3ng-theo-m%C3%A0u/
(defun c:cisov(/ _table _vlacol lays adoc col)
	(vl-load-com) 
	(defun _table (s / d r)
		(while (setq d (tblnext s (null d)))
			(setq r (append  (list (cons (cdr (assoc 2 d)) (cdr (assoc 62 d)))) r))
		)	
	)
	(defun _vlacol(obj lays / col)(if (/= (setq col (vla-get-color obj)) 256) col (cdr (assoc (vla-get-layer obj) lays))))
	(setq lays (_table "LAYER"))
	(setq adoc (vla-get-activedocument (vlax-get-acad-object)))
	(setq col (_vlacol (vlax-ename->vla-object (car(entsel))) lays)) 
	(vla-startundomark adoc)
	(vlax-for block (vla-get-blocks adoc)     
		  (vlax-for   ent block 
			(if (/= (_vlacol ent lays) col) (vla-put-visible ent 0))
		)
	)
	(vla-endundomark adoc)
)

(defun c:cunisov(/ adoc)
	(vl-load-com) 	
	(setq adoc (vla-get-activedocument (vlax-get-acad-object)))	
	(vlax-for block (vla-get-blocks adoc)     
		  (vlax-for   ent block 
			(vla-put-visible ent 1)
		)
	)
)

Thảo luận gốc

Lisp được chia sẻ trong chủ đề [Yêu cầu] Ẩn hiện đối tượng theo màu. Xem đúng bài viết #268211 để đọc hướng dẫn và trao đổi thêm.

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