Jump to content

List all layers and how many objects on each layer


Recommended Posts

Posted

Hello,

 

I am trying to put together a lisp or tool that I could list all the layers in the current DWG and how many objects are on each layer, and send it to a text file.

 

There are plenty of lisps out there that will allow listing all the layers, but that is it.

 

Thank you,

Posted

Hi,

 

Here is one I created, it should work for you. It's a bit big to post, so it's here as an attachment.

 

Have a good one.

Shawndoe

LayerList1-4.lsp

Posted

Would this not be sufficient:

 

(defun c:laylst (/ file ss lst)
 (vl-load-com)
 (if (setq file (getfiled "Output File" "" "txt" 9))
   (progn
     (vlax-for lay
       (vla-get-layers
         (vla-get-ActiveDocument
           (vlax-get-acad-object)))
       (if (setq ss (ssget "_X" (list (cons 8 (vla-get-Name lay)))))
         (setq lst (cons (cons (vla-get-Name lay) (sslength ss)) lst))))
     (setq file (open file "a"))
     (mapcar
       (function
         (lambda (x)
           (write-line
             (strcat (car x) (chr 32) (rtos (cdr x) 2 0)) file))) lst)))
 (princ))

Posted

Slight variation:

(defun c:laylst (/ layers file ss lst)
 (vl-load-com)
 (if (setq file (getfiled "Output File" "" "txt" 9))
   (progn
     (vlax-for lay (vla-get-layers(vla-get-ActiveDocument(vlax-get-acad-object)))
       (setq layers (cons (vla-get-Name lay) layers))
     )
     (setq layers (acad_strlsort layers))
     (mapcar (function (lambda(x)
       (if (setq ss (ssget "_X" (list (cons 8 x))))
         (setq lst (cons (list x (itoa (sslength ss))) lst))))) layers)
     (if (and lst (setq file (open file "a")))
       (progn
         (mapcar (function (lambda (x)
           (write-line (strcat (car x) "  :-->  " (cadr x)) file)))
           (reverse lst)
         )
         (close file)
         (prompt (strcat "\nLayers reported:  " (itoa (length lst))))
       )
     )
   )
 )
 (princ)
)

P.S. you didn't close your file.:)

Posted
P.S. you didn't close your file.:)

 

I always forget that dammit... :P

Posted

My wife leaves the back door open all the time, so you're in good company. :)

Posted

Well thank you much guys. Essentially I was on the right track, my only problem was I was trying to right it in straight autolisp. The shortened VBA helped out allot, and I was able to make it work with what I had.:shock:

Posted

My routine has much more coe then it needs to run single drawings, but it was actually written to run in batch runs as well as single drawings. it makes it much bigger then it needs to be. I originally wrote it as part of a drawing clean up job to look for layers that were misnamed or in some other way were non standard.

 

Glad you found what you needed.

 

Have a good one.

Shawndoe

Posted
My wife leaves the back door open all the time, so you're in good company. :)

 

ahem!!:shock:

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