See the top rated post in this thread. Click here

Page 1 of 2 12 LastLast
Results 1 to 10 of 14

Thread: Count the number of Layers with a specific character in the Layer name

  1. #1
    Member
    Join Date
    2005-06
    Posts
    2
    Login to Give a bone
    0

    Default Count the number of Layers with a specific character in the Layer name

    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

  2. #2
    All AUGI, all the time Avatart's Avatar
    Join Date
    2004-06
    Location
    Upsidedown in dreamtown
    Posts
    928
    Login to Give a bone
    0

    Default Re: Count the number of Layers with a specific character in the Layer name

    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.

  3. #3
    AUGI Addict
    Join Date
    2005-08
    Posts
    1,043
    Login to Give a bone
    0

    Default Re: Count the number of Layers with a specific character in the Layer name

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

  4. #4
    All AUGI, all the time CAB2k's Avatar
    Join Date
    2016-01
    Location
    Brandon, Florida
    Posts
    687
    Login to Give a bone
    0

    Default Re: Count the number of Layers with a specific character in the Layer name

    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

  5. #5
    All AUGI, all the time Avatart's Avatar
    Join Date
    2004-06
    Location
    Upsidedown in dreamtown
    Posts
    928
    Login to Give a bone
    0

    Default Re: Count the number of Layers with a specific character in the Layer name

    Don't half make my code look cumbersome!

  6. #6
    AUGI Addict
    Join Date
    2005-08
    Posts
    1,043
    Login to Give a bone
    0

    Default Re: Count the number of Layers with a specific character in the Layer name

    Thanks Alan.
    But wouldn't you need to 'strcase' the layer name pulled also then?
    ie:
    Code:
    (if (wcmatch (cdr (assoc 2 LayEnt)) String)
    to
    Code:
    (if (wcmatch (strcase (cdr (assoc 2 LayEnt))) String)

  7. #7
    AUGI Addict
    Join Date
    2005-08
    Posts
    1,043
    Login to Give a bone
    1

    Default Re: Count the number of Layers with a specific character in the Layer name

    Quote Originally Posted by carl_hd_collins
    Don't half make my code look cumbersome!
    Didn't mean to. It's just there are so many way to do anything in lisp, I thought I would show another.

  8. #8
    All AUGI, all the time Avatart's Avatar
    Join Date
    2004-06
    Location
    Upsidedown in dreamtown
    Posts
    928
    Login to Give a bone
    0

    Default Re: Count the number of Layers with a specific character in the Layer name

    Quote Originally Posted by T.Willey
    Didn't mean to. It's just there are so many way to do anything in lisp, I thought I would show another.
    Tim, your code is light years ahead of mine, I just sort of bludgeon it into submission, yours is elegant, nice one!

  9. #9
    All AUGI, all the time CAB2k's Avatar
    Join Date
    2016-01
    Location
    Brandon, Florida
    Posts
    687
    Login to Give a bone
    0

    Default Re: Count the number of Layers with a specific character in the Layer name

    Tim,
    You're quite right. I revised the posted code.

  10. #10
    AUGI Addict
    Join Date
    2005-08
    Posts
    1,043
    Login to Give a bone
    0

    Default Re: Count the number of Layers with a specific character in the Layer name

    Thanks guys! Now if we could only get the OP to come back and say it works for them.

Page 1 of 2 12 LastLast

Similar Threads

  1. Replies: 2
    Last Post: 2014-03-04, 03:43 PM
  2. Replies: 11
    Last Post: 2013-04-02, 05:27 AM
  3. Maximum character count for an inputted parameter
    By petervanko in forum Revit Architecture - General
    Replies: 1
    Last Post: 2009-07-28, 08:28 PM
  4. Prefix Filenames with Project Number - Change Character
    By bradg in forum Project Navigator
    Replies: 0
    Last Post: 2008-11-13, 09:08 PM
  5. Replies: 5
    Last Post: 2005-12-15, 08:05 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •