Jump to content

List of Layers with No of Entities


Recommended Posts

Posted

Dear Colleagues;

 

 

Thanks for this site and everyone that posts on it....

I have recieved a lots of great infor. just reading through forums.

I need to know that Is there any lisp for output the

List of Layers with No of Entities from a dwg. as attached Image

 

 

Thanks

Romano

Layer List.jpg

Posted

The Layer Manager already has this ability, granted not exactly how you're inquiring about. The Status column (the very first column to the left of the Name column) has a trapezoid icon next to each layer. If this icon is grayed out, there is no entities on this layer. If it is blue, it hosts at least one entity. This doesn't give you a report of how many entities but does give you a "yes/no" scenario. You can also sort this column as well.

 

Hope this workaround is good enough for your needs. You'd surely need a programmer to add that type of column to the Layer Manager.

 

8)

Posted

Do you want to physically print out the list of unused layers or merely display it on the screen? If you only want to display the list, open the layer manager, click on All Used Layers in the layer tree list at the left, then click on the Invert (reverse) filter box at the bottom left. This displays all the unused layers. If you want, they can be deleted using this list.

Posted

Thanks for the Reply to my Thread

 

 

Simply when you purge the drawing .......

the layers with No Entities deletes

 

 

But I want the List of Layers with No. of Entities

Because when you work with others file they unnecessary creates more layers

to reduces the layers

 

 

Happy christmas wishes to all you in Advance...

Thanks

Romano

Posted

ToolPac by DotSoft has the ability to count objects by layer.

 

Object Count by Layer: Layer Object Count breakdown by type with report or optional table. Look under the "Inquiry" section.

Posted (edited)

The following will produce a report detailing the number of objects on each layer in the active drawing, including primary & nested objects, objects within block definitions, and attribute references.

 

The list is sorted in decreasing order of number of objects:

;; Layer Count  -  Lee Mac
;; Prints a report of the number of objects on each layer in a drawing

(defun c:layercount ( / lst )    
   (vlax-for blk (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object)))
       (vlax-for obj blk
           (setq lst (layercount:assoc++ (vla-get-layer obj) lst))
           (if
               (and
                   (= "AcDbBlockReference" (vla-get-objectname obj))
                   (= :vlax-true (vla-get-hasattributes obj))
               )
               (foreach att (vlax-invoke obj 'getattributes)
                   (setq lst (layercount:assoc++ (vla-get-layer att) lst))
               )
           )
       )
   )
   (princ (layercount:padbetween "\n\n" "" "-" 62))
   (princ (layercount:padbetween "\nLayer" "Objects" " " 61))
   (princ (layercount:padbetween "\n" "" "-" 61))
   (foreach itm (vl-sort lst '(lambda ( a b ) (> (cdr a) (cdr b))))
       (princ (layercount:padbetween (strcat "\n" (car itm)) (itoa (cdr itm)) "." 61))
   )
   (princ (layercount:padbetween "\n" "" "-" 61))
   (princ (layercount:padbetween "\nTotal" (itoa (apply '+ (mapcar 'cdr lst))) "." 61))
   (princ (layercount:padbetween "\n" "" "-" 61))
   (textpage)
   (princ)
)
(defun layercount:assoc++ ( key lst / itm )
   (if (setq itm (assoc key lst))
       (subst (cons key (1+ (cdr itm))) itm lst)
       (cons  (cons key 1) lst)
   )
)
(defun layercount:padbetween ( s1 s2 ch ln )
   (
       (lambda ( a b c )
           (repeat (- ln (length b) (length c)) (setq c (cons a c)))
           (vl-list->string (append b c))
       )
       (ascii ch)
       (vl-string->list s1)
       (vl-string->list s2)
   )
)        
(vl-load-com) (princ)
 

It may be slow for large drawings.

Edited by Lee Mac
Posted
Thanks for the Reply to my Thread

 

 

Simply when you purge the drawing .......

the layers with No Entities deletes

 

 

But I want the List of Layers with No. of Entities

Because when you work with others file they unnecessary creates more layers

to reduces the layers

 

 

Happy christmas wishes to all you in Advance...

Thanks

Romano

Oh, No. of Entities. I think at least two of us thought it was No entities. Reading too fast and a missing period, I guess. It appears that the lisp gods have descended, and have you well in hand though.
Posted
The Layer Manager already has this ability, granted not exactly how you're inquiring about. The Status column (the very first column to the left of the Name column) has a trapezoid icon next to each layer. If this icon is grayed out, there is no entities on this layer. If it is blue, it hosts at least one entity. This doesn't give you a report of how many entities but does give you a "yes/no" scenario. You can also sort this column as well.

 

Hope this workaround is good enough for your needs. You'd surely need a programmer to add that type of column to the Layer Manager.

 

8)

Just as a note, this didn't work for me? Until I found there is a variable that controls it (showlayerusage) if it is set to zero then all the trapezoids remain blue
Posted

Hi all;

 

 

My warm thanks goes to Mr. Lee Mac (amazing)

I wanted to thank you but then I realized I don’t know where to begin.

So, I just wanted to say that there are so many things I couldn’t have done without you.

Words are not enough to express my gratitude for you.

Thank you all replied to my thread for your love and support!

 

 

Best Regards

Romano

Posted
Hi all;

My warm thanks goes to Mr. Lee Mac (amazing)

....

So, I just wanted to say that there are so many things I couldn’t have done without you.

 

Indeed it is, I'm loving lassoc++ sub from LM's routine :thumbsup:

 

Taught LM everything he knows so far....:lol:

 

Seriously, one thing i notice the lst includes the default viewport and the contents of a block definition as well even though no blocks are inserted on the drawing session [space that is]

 

EDIT: question now is that included and count as entities since purging the drawing will delete those "not use in drawings" objects? (curious is all) :)

Posted
My warm thanks goes to Mr. Lee Mac (amazing)

I wanted to thank you but then I realized I don’t know where to begin.

So, I just wanted to say that there are so many things I couldn’t have done without you.

Words are not enough to express my gratitude for you.

Thank you all replied to my thread for your love and support!

 

That is very kind of you to say Romano!

I'm glad to be able to assist you, and I appreciate your gratitude!

 

Indeed it is, I'm loving lassoc++ sub from LM's routine :thumbsup:

 

Cheers pBe -

I made a nested version too if you're interested. :)

 

Seriously, one thing i notice the lst includes the default viewport and the contents of a block definition as well even though no blocks are inserted on the drawing session [space that is]

 

Yes, the current draft simply includes everything in the drawing database - this could of course be refined to report only visible objects, but I couldn't spend too long on it...

  • 4 years later...
Posted
On ‎12‎/‎16‎/‎2013 at 3:48 PM, Lee Mac said:

The following will produce a report detailing the number of objects on each layer in the active drawing, including primary & nested objects, objects within block definitions, and attribute references.

 

The list is sorted in decreasing order of number of objects:

 


[color=GREEN];; Layer Count  -  Lee Mac[/color]
[color=GREEN];; Prints a report of the number of objects on each layer in a drawing[/color]

([color=BLUE]defun[/color] c:layercount ( [color=BLUE]/[/color] lst )    
   ([color=BLUE]vlax-for[/color] blk ([color=BLUE]vla-get-blocks[/color] ([color=BLUE]vla-get-activedocument[/color] ([color=BLUE]vlax-get-acad-object[/color])))
       ([color=BLUE]vlax-for[/color] obj blk
           ([color=BLUE]setq[/color] lst (layercount:assoc++ ([color=BLUE]vla-get-layer[/color] obj) lst))
           ([color=BLUE]if[/color]
               ([color=BLUE]and[/color]
                   ([color=BLUE]=[/color] [color=MAROON]"AcDbBlockReference"[/color] ([color=BLUE]vla-get-objectname[/color] obj))
                   ([color=BLUE]=[/color] [color=BLUE]:vlax-true[/color] ([color=BLUE]vla-get-hasattributes[/color] obj))
               )
               ([color=BLUE]foreach[/color] att ([color=BLUE]vlax-invoke[/color] obj 'getattributes)
                   ([color=BLUE]setq[/color] lst (layercount:assoc++ ([color=BLUE]vla-get-layer[/color] att) lst))
               )
           )
       )
   )
   ([color=BLUE]princ[/color] (layercount:padbetween [color=MAROON]"\n\n"[/color] [color=MAROON]""[/color] [color=MAROON]"-"[/color] 62))
   ([color=BLUE]princ[/color] (layercount:padbetween [color=MAROON]"\nLayer"[/color] [color=MAROON]"Objects"[/color] [color=MAROON]" "[/color] 61))
   ([color=BLUE]princ[/color] (layercount:padbetween [color=MAROON]"\n"[/color] [color=MAROON]""[/color] [color=MAROON]"-"[/color] 61))
   ([color=BLUE]foreach[/color] itm ([color=BLUE]vl-sort[/color] lst '([color=BLUE]lambda[/color] ( a b ) ([color=BLUE]>[/color] ([color=BLUE]cdr[/color] a) ([color=BLUE]cdr[/color] b))))
       ([color=BLUE]princ[/color] (layercount:padbetween ([color=BLUE]strcat[/color] [color=MAROON]"\n"[/color] ([color=BLUE]car[/color] itm)) ([color=BLUE]itoa[/color] ([color=BLUE]cdr[/color] itm)) [color=MAROON]"."[/color] 61))
   )
   ([color=BLUE]princ[/color] (layercount:padbetween [color=MAROON]"\n"[/color] [color=MAROON]""[/color] [color=MAROON]"-"[/color] 61))
   ([color=BLUE]princ[/color] (layercount:padbetween [color=MAROON]"\nTotal"[/color] ([color=BLUE]itoa[/color] ([color=BLUE]apply[/color] '[color=BLUE]+[/color] ([color=BLUE]mapcar[/color] '[color=BLUE]cdr[/color] lst))) [color=MAROON]"."[/color] 61))
   ([color=BLUE]princ[/color] (layercount:padbetween [color=MAROON]"\n"[/color] [color=MAROON]""[/color] [color=MAROON]"-"[/color] 61))
   ([color=BLUE]textpage[/color])
   ([color=BLUE]princ[/color])
)
([color=BLUE]defun[/color] layercount:assoc++ ( key lst [color=BLUE]/[/color] itm )
   ([color=BLUE]if[/color] ([color=BLUE]setq[/color] itm ([color=BLUE]assoc[/color] key lst))
       ([color=BLUE]subst[/color] ([color=BLUE]cons[/color] key ([color=BLUE]1+[/color] ([color=BLUE]cdr[/color] itm))) itm lst)
       ([color=BLUE]cons[/color]  ([color=BLUE]cons[/color] key 1) lst)
   )
)
([color=BLUE]defun[/color] layercount:padbetween ( s1 s2 ch ln )
   (
       ([color=BLUE]lambda[/color] ( a b c )
           ([color=BLUE]repeat[/color] ([color=BLUE]-[/color] ln ([color=BLUE]length[/color] b) ([color=BLUE]length[/color] c)) ([color=BLUE]setq[/color] c ([color=BLUE]cons[/color] a c)))
           ([color=BLUE]vl-list->string[/color] ([color=BLUE]append[/color] b c))
       )
       ([color=BLUE]ascii[/color] ch)
       ([color=BLUE]vl-string->list[/color] s1)
       ([color=BLUE]vl-string->list[/color] s2)
   )
)        
([color=BLUE]vl-load-com[/color]) ([color=BLUE]princ[/color])
 

 

It may be slow for large drawings.

Would like to use this but I can not figure out how to run this... Can you point me into the correct direction please.

Posted

Here is that code in usable form - BBC code tags removed...

 

;; Layer Count  -  Lee Mac
;; Prints a report of the number of objects on each layer in a drawing

(defun c:layercount ( / lst )   
  (vlax-for blk (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object)))
      (vlax-for obj blk
          (setq lst (layercount:assoc++ (vla-get-layer obj) lst))
          (if
              (and
                  (= "AcDbBlockReference" (vla-get-objectname obj))
                  (= :vlax-true (vla-get-hasattributes obj))
              )
              (foreach att (vlax-invoke obj 'getattributes)
                  (setq lst (layercount:assoc++ (vla-get-layer att) lst))
              )
          )
      )
  )
  (princ (layercount:padbetween "\n\n" "" "-" 62))
  (princ (layercount:padbetween "\nLayer" "Objects" " " 61))
  (princ (layercount:padbetween "\n" "" "-" 61))
  (foreach itm (vl-sort lst '(lambda ( a b ) (> (cdr a) (cdr b))))
      (princ (layercount:padbetween (strcat "\n" (car itm)) (itoa (cdr itm)) "." 61))
  )
  (princ (layercount:padbetween "\n" "" "-" 61))
  (princ (layercount:padbetween "\nTotal" (itoa (apply '+ (mapcar 'cdr lst))) "." 61))
  (princ (layercount:padbetween "\n" "" "-" 61))
  (textpage)
  (princ)
)
(defun layercount:assoc++ ( key lst / itm )
  (if (setq itm (assoc key lst))
      (subst (cons key (1+ (cdr itm))) itm lst)
      (cons  (cons key 1) lst)
  )
)
(defun layercount:padbetween ( s1 s2 ch ln )
  (
      (lambda ( a b c )
          (repeat (- ln (length b) (length c)) (setq c (cons a c)))
          (vl-list->string (append b c))
      )
      (ascii ch)
      (vl-string->list s1)
      (vl-string->list s2)
  )
)       

(vl-load-com) (princ)

 

Posted (edited)
2 hours ago, lemacs said:

Would like to use this but I can not figure out how to run this... Can you point me into the correct direction please.

 

Unfortunately when CADTutor transitioned from vBulletin to the new Invision forum software, BBCode (e.g. color tags) are no longer permitted within code blocks and are consequently now displayed as part of the code itself.

 

You can quite easily remove the color tags in Notepad++ using the following Find/Replace:

npbbcoderegex.png.1e9879993ec2313c40869152a883e8b8.png

 

The RegEx pattern I've used here is:

\[color=[^\]]+\]|\[\/color\]

 

Edited by Lee Mac
  • Like 2
  • 1 year later...
Posted

i need lisp layer count but i need not the all layers in the drawing

just i want select object and lisp will give me which layer and how many are they

can some one help me?

 

Posted

If not interested in entities in a block being on picked layer. Then a very simple.

 

(while (setq ent (entsel "\nSelect object <Enter> to exit "))
(setq lay (cdr (assoc 8 (entget (car ent)))))
(setq ss (ssget "x" (list (cons 8 lay))))
(alert (strcat "There are " (rtos (sslength ss) 2 0) " Objects on layer " lay))
)

 

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