Hi everyone,
I,m looking for a routine in pure Autolisp to count the number of layers with a specific character in the layer-name. I.e. count all layers beginning with "s-".
Thank you
christoph
|
Hi everyone,
I,m looking for a routine in pure Autolisp to count the number of layers with a specific character in the layer-name. I.e. count all layers beginning with "s-".
Thank you
christoph
I had something similar already done, I chopped it about a bit and here is the result:
Code:;; Get Layer List ;; from Drawing (defun C:S-Layers ( / newelem laylist searchparam listlength searchparamtext) (setq searchparamtext (getstring T "\nEnter Layer search parameter: ")) (setq searchparam (strcat "*" searchparamtext "*")) (setq newelem (tblnext "layer" T)); Get first Layer (if (= (wcmatch (cdr (assoc 2 newelem)) searchparam) T) (setq newelem (cdr (assoc 2 (tblnext "layer" T)))) (setq newelem nil)); Start Layer List (if (/= nil newelem) (setq laylist (append laylist newelem))); Add to Layer list if appropriate (while (/= (setq newelem (tblnext "layer")) nil); Start loop for remaining layers (if (= (wcmatch (cdr (assoc 2 newelem)) searchparam) T) (setq newelem (list (cdr (assoc 2 newelem)))) (setq newelem nil)); Check each Layer (if (/= nil newelem) (setq laylist (append laylist newelem)))); Add to Layer list if appropriate (setq laylist (acad_strlsort laylist)) (setq listlength (rtos (length laylist) 2 0)) (alert (strcat "There are " listlength " layers that contain \"" searchparamtext "\"")) )
Last edited by Avatart; 2007-03-15 at 03:10 PM.
Code:( (lambda (String / cnt LayEnt flag) (setq cnt 0) (while (setq LayEnt (tblnext "layer" (not flag))) (if (wcmatch (cdr (assoc 2 LayEnt)) String) (setq cnt (1+ cnt)) ) (setq flag T) ) (prompt (strcat "\n " (itoa cnt) " layer(s) found.")) ) "s-*" )
Nice one Tim.
A suggestion to make it case insensitive.
Code:((lambda (String / cnt LayEnt) (setq cnt 0 String (strcase String)) (while (setq LayEnt (tblnext "layer" (not LayEnt))) (if (wcmatch (strcase (cdr (assoc 2 LayEnt))) String) (setq cnt (1+ cnt)) ) ) (princ (strcat "n " (itoa cnt) " layer(s) found.")) ) "s-*" )
Last edited by CAB2k; 2007-03-15 at 04:39 PM. Reason: Code Correction by Tim
Don't half make my code look cumbersome!
Thanks Alan.
But wouldn't you need to 'strcase' the layer name pulled also then?
ie:
toCode:(if (wcmatch (cdr (assoc 2 LayEnt)) String)
Code:(if (wcmatch (strcase (cdr (assoc 2 LayEnt))) String)
Didn't mean to. It's just there are so many way to do anything in lisp, I thought I would show another.Originally Posted by carl_hd_collins
Tim, your code is light years ahead of mine, I just sort of bludgeon it into submission, yours is elegant, nice one!Originally Posted by T.Willey
Tim,
You're quite right. I revised the posted code.
Thanks guys! Now if we could only get the OP to come back and say it works for them.