Jump to content

Count of object in specific layer


RepCad

Recommended Posts

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
Link to comment
Share on other sites

(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
Link to comment
Share on other sites

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

Which part of my code is wrong??

Edited by amir0914
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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]. :)

Link to comment
Share on other sites

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
Link to comment
Share on other sites

  • 2 weeks later...

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

Link to comment
Share on other sites

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