Jump to content
amir0914

Count of object in specific layer

Recommended Posts

amir0914

hi guys, i need a lisp to get Count of Object in a specific layer by get layer name, can someone help me? 

Share this post


Link to post
Share on other sites
amir0914

hi thanks, i have seen that topic already, but i want to know count of object only in one layer, i wrote this code but it doesn't work : (sorry i'm beginner in autolisp)

 

(defun c:LC ()

  (setq acadObj (vlax-get-acad-object))
  (setq doc (vla-get-ActiveDocument acadObj))

  (setq cnt (vla-get-Count (vla-item (vla-get-Layers doc) "Wall")))
)

"Wall" is layer name

Edited by amir0914

Share this post


Link to post
Share on other sites
marko_ribar
(defun c:LC nil
  (if (ssget "_X" '((8 . "Wall")))
    (progn
      (prompt "\nTotal : ") (princ (sslength (ssget "_X" '((8 . "Wall"))))) (prompt " entities in Layer : \"Wall\"")
    )
    (prompt "\nNo entities in Layer : \"Wall\"")
  )
  (princ)
)

 

  • Like 1

Share this post


Link to post
Share on other sites
amir0914

Thank you marko, i used your code and my problem is resolved, 

Which part of my code is wrong??

Edited by amir0914

Share this post


Link to post
Share on other sites
BIGAL

A little add on not hard codedfor layer name.

(defun c:LC ( / layname )
  (setq layname (vla-get-layer (vlax-ename->vla-object (car (entsel)))))
  (if (setq ss (ssget "_X" (list (cons 8 layname))))
    (Alert  (strcat "\nTotal : " (rtos (sslength ss) 2 0) " entities \n\nIn Layer : " layname))
    (Alert (strcat "\nNo entities in Layer : " layname))
  )
  (princ)
)
(c:lc)

 

 (vla-get-Layers doc) this gets the list of layer names from the layer table, not objects within that layer.

Edited by BIGAL
  • Like 1

Share this post


Link to post
Share on other sites
Lee Mac
17 hours ago, amir0914 said:

Which part of my code is wrong??

 

A VLA Layer object does not have a count property - you can check the available properties & methods for an object using the vlax-dump-object function.

  • Like 1

Share this post


Link to post
Share on other sites
ronjonp
11 hours ago, BIGAL said:

(setq ss (ssget "_X" (list (cons 8 layname

I think you're missing a few closing parenthesis 😉

  • Like 1

Share this post


Link to post
Share on other sites
BIGAL

Thanks ronjonp must have cut and pasted wrong.

  • Like 1

Share this post


Link to post
Share on other sites
amir0914

Thank you  all for your honest help and advice, 

lee Mac, I check and study vlax-dump-object , it was useful and great.

Share this post


Link to post
Share on other sites
Lee Mac
1 hour ago, amir0914 said:

Thank you  all for your honest help and advice, 

lee Mac, I check and study vlax-dump-object , it was useful and great.

 

You're most welcome @amir0914 - You may find my Dump Object utility useful in this regard - it's a simple program and merely a wrapper for the vlax-dump-object function to allow you to select a primary or nested object.

  • Like 1

Share this post


Link to post
Share on other sites
Grrr
4 hours ago, Lee Mac said:

You may find my Dump Object utility useful in this regard - it's a simple program and merely a wrapper for the vlax-dump-object function

 

Lee, just an idea for fun - you could include accepting a handle argument [STR]. :)

Share this post


Link to post
Share on other sites
Lee Mac
1 hour ago, Grrr said:

Lee, just an idea for fun - you could include accepting a handle argument [STR]. :)

 

An excellent idea Grrr!

I have now updated the utility to achieve exactly that - I've also rewritten it to handle the various data types more elegantly - thank you for this suggestion. :thumbsup:

Edited by Lee Mac
  • Like 1

Share this post


Link to post
Share on other sites
amir0914

Thank you Lee mac, Sorry for the delay in replying, I see your website and post about Dump-Object, I'm sure it will help me a lot , thanks again..

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×