Jump to content

How to count blocks with attributes only?


Recommended Posts

Posted

I have been searching forum a while, no definative answer.

 

I need to count how many blocks are in a drawing but only those that contain attributes.

I can't seem to do this with the filter command as it only shows number of all blocks regardless of whether they contain attributes or not.

 

Is this do-able via search options or would it be a lisp thing?

 

Many thanks

Posted

In LISP, it could be:

 

(defun c:test ( / a )
 (if (setq a (ssget "_X" '((0 . "INSERT") (66 . 1))))
   (princ (strcat "\nThere are " (itoa (sslength a)) " attributed blocks in the Drawing."))
   (princ "\nThere are no attributed blocks in the Drawing.")
 )
 (princ)
)

 

Or perhaps more grammatically correct:

 

(defun c:test ( / a )
 (princ
   (cond
     ( (not (setq a (ssget "_X" '((0 . "INSERT") (66 . 1)))))

       "\nThere are no attributed blocks in the Drawing."
     )
     ( (= 1 (sslength a))

       "\nThere is 1 attributed block in the Drawing."
     )
     ( (strcat "\nThere are " (itoa (sslength a)) " attributed blocks in the Drawing.") )
   )    
 )
 (princ)
)

Posted

Wow, did you cut and paste that or do people actually code as fast as the show in films?

 

yes that seems along the lines Lee. Thank you.

 

I assume that counts all the model space and paper space blocks as a whole? So it would pick up likes of drawing borders etc in the paperspace.

 

How difficult would it be to add the option to count only the attributed blocks in a selection?

Posted

Hi SpaceCadet,

 

Didn't cut and paste, just typed it :)

 

To count all in selection only, remove the "_X" from the ssget function.

Posted
Why do I always kill threads :(

 

Maybe it is your avatar.

Posted

HA.

 

Nonsense! The monocle smile would never do such things.

Posted

Why do I always get sent out of the office when i'm trying to get answers. Back at the workstation now.

 

re:data extraction. It's during this process that the number I need to check seems to disappear.

 

I am doing a check that the number of blocks (with attributes) in the drawing is equal to the number that end up in the excel file after extraction.

If we have a mixture of attributed blocks and non-attributed blocks in a drawing The filtered search result gives me all blocks.

I then dx and tick boxes to extract only blocks with attributes, but it doesn't tell me in that process what the total number of those attributed blocks is...

 

Does any of this make sense?

Ideally it would be good if during the extraction process when you tick a box in the settings it could tell you "you now have xxx block selected for extraction"

Posted
Hi SpaceCadet,

 

Didn't cut and paste, just typed it :)

 

To count all in selection only, remove the "_X" from the ssget function.

 

yes that worked. Excellent.

 

Sorry all got sent out of the office...always good to get out though. They keep me in a basement you know!

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