Jump to content

Layer check error


j_spawn_h

Recommended Posts

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.

Link to comment
Share on other sites

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)

Link to comment
Share on other sites

Something like this?

 

(defun c:foo ()
 (if (tblsearch "layer" "mylayer")
   (do_your_stuff_here)
   (alert "Mylayer not found")  
 )
 (princ)
)

pwned HAHA

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...