j_spawn_h Posted March 14, 2013 Share Posted March 14, 2013 I want to add in my lisp to check for a layer in the drawing before the lisp runs. If there cont. if not there maybe pop a box or in the command line say the layer is missing then end the lisp. I know it has been done before but my search is not finding any thing. Quote Link to comment Share on other sites More sharing options...
fabriciorby Posted March 14, 2013 Share Posted March 14, 2013 try this, it's case sensitive i just changed something from here http://www.afralisp.net/visual-lisp/tutorials/visual-lisp-and-layers.php (defun C:laycheck ( / acadobject activedocument LayerTable layname cont) (vl-load-com) (setq cont 0) (setq layname(getstring "type the layer name pls\n")) (setq acadobject (vlax-get-Acad-Object)) (setq activedocument (vla-get-activedocument acadobject)) (setq LayerTable (vla-get-layers activedocument)) (vlax-for each LayerTable (if (= (vla-get-name each) layname) (setq cont 1) ) ) (if (= cont 1) (progn ;continue code.... ) (alert "the layer is missing") ) ) (princ) Quote Link to comment Share on other sites More sharing options...
rkmcswain Posted March 14, 2013 Share Posted March 14, 2013 Something like this? (defun c:foo () (if (tblsearch "layer" "mylayer") (do_your_stuff_here) (alert "Mylayer not found") ) (princ) ) Quote Link to comment Share on other sites More sharing options...
fabriciorby Posted March 14, 2013 Share Posted March 14, 2013 Something like this? (defun c:foo () (if (tblsearch "layer" "mylayer") (do_your_stuff_here) (alert "Mylayer not found") ) (princ) ) pwned HAHA Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted March 15, 2013 Share Posted March 15, 2013 For what its worth fabriciorby, here is another way to use Visual LISP to test for the existence of a layer in the active drawing: (Note that the function could equally be written to test for the existence of any item in any Visual LISP Collection object residing in the active drawing or elsewhere). (defun layerexists-p ( layer ) (not (vl-catch-all-error-p (vl-catch-all-apply 'vla-item (list (vla-get-layers (vla-get-activedocument (vlax-get-acad-object))) layer) ) ) ) ) (vl-load-com) Though the tblsearch method as demostrated above is of course much faster and usually applicable in most cases (unless working through ObjectDBX). Quote Link to comment Share on other sites More sharing options...
rkmcswain Posted March 15, 2013 Share Posted March 15, 2013 For what its worth fabriciorby, here is another way to use Visual LISP.... Reminds me of a story Lee. We once had some code here (written by someone else) in VBA that did some layer checking at startup. It was really slow, and for no obvious reason to end users, so I started looking at it one day. (a) The function iterated every single layer in the collection, meaning that it didn't stop when it found the one it was looking for (and we had drawings with 700 or more layers) (b) The function was called over and over, testing for ±20 layers, meaning..... time to do step "a" X 20. IIRC - I was able to get the startup time of this routine down from ±15 seconds to almost instantly Quote Link to comment Share on other sites More sharing options...
fabriciorby Posted March 15, 2013 Share Posted March 15, 2013 For what its worth fabriciorby, here is another way to use Visual LISP to test for the existence of a layer in the active drawing:(Note that the function could equally be written to test for the existence of any item in any Visual LISP Collection object residing in the active drawing or elsewhere). Thank you, Lee. I'll keep practing haha Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.