Hello everyone
I found this great code by Kent which toggles layer on/off and works great except it shows error (bad argument type: lentityp nil) when one of the layers dont exist. How can I make it ignore the error (not print in command line)? Please help.....Thanks in advance!
(defun C:demo () (layertoggle "myLayer01") (layertoggle "myLayer02") ) (defun layertoggle (layname / laydata) (setq laydata (entget (tblobjname "layer" layname)) laydata (subst (cons 70 (boole 6 (cdr (assoc 70 laydata)) 1)) (assoc 70 laydata) laydata ) ) (entmod laydata) )
Solved! Go to Solution.
Solved by Kent1Cooper. Go to Solution.
@JCprog wrote:
....
I found this great code by Kent which toggles layer on/off and works great except it shows error (bad argument type: lentityp nil) when one of the layers dont exist. How can I make it ignore the error (not print in command line)? ....
(defun layertoggle (layname / laydata)
(if (tblsearch "layer" layname); does the Layer exist?
(progn ; then
(setq
laydata (entget (tblobjname "layer" layname))
laydata (subst (cons 70 (boole 6 (cdr (assoc 70 laydata)) 1)) (assoc 70 laydata) laydata)
)
(entmod laydata)
); progn
); if
)
FWIW, there is no need to use both tblsearch and tblobjname, since tblobjname will return nil if the layer doesn't exist, e.g.:
(defun layertoggle ( lay / dxf ) (if (setq lay (tblobjname "layer" lay)) (entmod (setq lay (entget lay) dxf (assoc 70 lay) lay (subst (cons 70 (boole 6 (cdr dxf) 1)) dxf lay) ) ) ) )