Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

If entity not found dont show error message

3 REPLIES 3
SOLVED
Reply
Message 1 of 4
JCprog
253 Views, 3 Replies

If entity not found dont show error message

Hello everyone Smiley Happy

 

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) )

 

3 REPLIES 3
Message 2 of 4
Kent1Cooper
in reply to: JCprog


@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

)

Kent Cooper, AIA
Message 3 of 4
JCprog
in reply to: Kent1Cooper

That works perfectly! Thanks Kent! Smiley Very Happy

Message 4 of 4
Lee_Mac
in reply to: JCprog

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)
            )
        )
    )
)

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost