<求助>按颜色显示/隐藏对象 总是出现致命错误
加载下面这段代码没事,但是运行的时候总是致命错误退出,我用2008和10都试过了,都一样,不知道是哪里错了、、、;YC1:隐藏选中的对象 ;YC2:隐藏同一颜色的对象 ;YC3:只显示选择颜色的对象 ;XS:显示所有隐藏的对象
(defun c:yc1 (/ ss ssn n)
(princ "\n请选择需要隐藏的对象:")
(setq ss (ssget))
(command "undo" "be")
(setvar "cmdecho" 0)
(setq n 0)
(while (< n (sslength ss))
(setq ssn (ssname ss n))
(setq ssn (entget ssn))
(setq ssn (append ssn '((60 . 1))))
;(setq ssn (cons '(60 . 1) ssn))
(entmod ssn)
(setq n (1+ n))
)
(command "undo" "e")
(princ)
)
(defun c:yc2 (/ ss ssn n cor m ss1 pd ssm)
(princ "\n请选择需要隐藏的颜色:")
(setq ss (nth 0 (entsel)))
(command "undo" "be")
(setvar "cmdecho" 0)
(setq cor (assoc 62 (entget ss))) ;颜色如果随层,按图层颜色
(if (= cor nil)
(progn (setq tc (cdr (assoc 8 (entget ss))))
(setq tc (tblsearch "layer" tc))
(setq cor (assoc 62 tc))
)
)
;;;找出不是随层符合颜色的对象
(setq ss (ssget "x" (list cor)))
(if (/= ss nil)
(progn (setq n 0)
(while (< n (sslength ss))
(setq ssn (ssname ss n))
(setq ssn (entget ssn))
(setq ssn (append ssn '((60 . 1))))
(entmod ssn)
(setq n (1+ n))
)
)
)
;;;找出随层符合颜色的对象
(setq tc (tblnext "layer" "0"))
(while (/= tc nil)
(if (equal cor (assoc 62 tc))
(progn (setq ss1 (ssget "x" (list (cons 8 (cdr (assoc 2 tc))))))
(if (/= ss1 nil)
(progn (setq m 0)
(while (< m (sslength ss1))
(setq ssm (entget (ssname ss1 m)))
(setq pd (assoc 62 ssm))
(if (= pd nil)
(progn (setq ssm (append ssm '((60 . 1)))) ;
(setq ssm (cons '(60 . 1) ssm))
(entmod ssm)
)
)
(setq m (1+ m))
)
)
)
)
)
(setq tc (tblnext "layer"))
)
(command "undo" "e")
(princ)
)
(defun c:yc3 (/ corss ssn cor ss corl n tc)
(princ "\n请选择不隐藏颜色:")
(setq ss (ssget))
(command "undo" "be")
(setvar "cmdecho" 0)
(setq corss (list))
(setq n 0)
(while (< n (sslength ss)) ;找出不关闭的颜色
(setq ssn (ssname ss n))
(setq cor (assoc 62 (entget ssn))) ;不随层
(if (= cor nil) ;随层
(progn (setq tc (cdr (assoc 8 (entget ssn))))
(setq tc (tblsearch "layer" tc))
(setq cor (assoc 62 tc))
)
)
(setq cor (cdr cor)) ;得到颜色
(setq corl (list cor))
(if (= nil (assoc cor corss))
(setq corss (cons corl corss))
)
(setq n (1+ n))
)
(princ "\n不隐藏颜色:")
(princ corss)
(setq ss (ssget "x" '()))
(setq n 0)
(while (< n (sslength ss))
(setq ssn (ssname ss n))
(setq cor (assoc 62 (entget ssn)))
(if (= cor nil)
(progn (setq tc (cdr (assoc 8 (entget ssn))))
(setq tc (tblsearch "layer" tc))
(setq cor (assoc 62 tc))
)
)
(setq cor (cdr cor)) ;得到颜色
(if (= nil (assoc cor corss)) ;如果不在表内隐藏
(progn (setq ssn (entget ssn))
(setq ssn (append ssn '((60 . 1))))
(entmod ssn)
)
)
(setq n (1+ n))
)
(command "undo" "e")
(princ)
)
(defun c:xs (/ ss ssn n)
(setq ss (ssget "x" (list (cons 60 1))))
(command "undo" "be")
(setvar "cmdecho" 0)
(setq n 0)
(while (< n (sslength ss))
(setq ssn (ssname ss n))
(setq ssn (entget ssn))
(setq ssn (subst (cons 60 0) (assoc 60 ssn) ssn))
(entmod ssn)
(setq n (1+ n))
)
(command "undo" "e")
)
用着很好啊 用着确实很好,没发现啥问题。 测试一切OK啊 隐藏选择颜色时(yc2),会有部分隐藏不掉,其他正常使用,实用
页:
[1]