Jump to content

Recommended Posts

Posted

Looking for a way to count instances of attribute value of a particular attribute tag. If possible a simple code for me to start with. Thanks.

Posted (edited)

If I understand correctly, this could be a start :

(defun c:att-qty (/ tag val q ss en ed an ad)

  (while (not (snvalid tag))
         (setq tag (strcase (getstring "\nValid TAG Name To Count:   "))))

  (setq val (getstring t "\nATTRIBute Value To Count:   "))

  (setq q 0)
  (and (setq ss (ssget "X" '((0 . "INSERT")(66 . 1))))
       (setq i 0)
       (while (setq en (ssname ss i))
              (setq ed (entget en)
                    an (entnext en)
                    ad (entget an))
              (while (= "ATTRIB" (cdr (assoc 0 ad)))
                     (and (= tag (cdr (assoc 2 ad)))
                          (= (strcase val)
                             (strcase (cdr (assoc 1 ad))))
                          (setq q (1+ q)))
                     (setq an (entnext an)
                           ad (entget an)))
              (setq i (1+ i))))
  (alert (strcat (itoa q) " " tag " ATTRIButtes Found"))
  (prin1))

 

The ATTRIB values are not case sensitive.

 

-David

Edited by David Bethel
Posted

Dear Paulo,

I got a code that can select the attributes with your input value, So you can see the no.of items in property box(CTRL+1).

 

(defun ssattval (val / ss res ref name blk)
  (vl-load-com)
  (or *acad* (setq *acad* (vlax-get-acad-object)))
  (or *acdoc* (setq *acdoc* (vla-get-ActiveDocument *acad*)))
  (setq res (ssadd))
  (if (ssget "_X" '((0 . "INSERT") (66 . 1)))
    (progn
      (vlax-for ref (setq ss (vla-get-ActiveSelectionSet *acdoc*))
        (setq has nil)
        (foreach att (vlax-invoke ref 'GetAttributes)
          (if (wcmatch (strcase (vla-get-TextString att)) (strcase val))
            (setq has T)
          )
        )
        (if has
          (ssadd (vlax-vla-object->ename ref) res)
        )
      )
      (vla-delete ss)
    )
  )
  (if (< 0 (sslength res))
    res
  )
)
 
(defun c:SLBKAT (/ val)
  (if (setq val (getstring "\Enter the value of attribute: "))
    (sssetfirst nil (ssattval val))
  )
  (princ)
)

Posted

That is more than just a start, David 😊. Cheers. Tnvsb, I have yet to get my hands on vlisp, Still looking for a good place to start on it, but thanks. Thanks also, Lee for the ready to use codes. I’d really would like to get my head to study your ways. But this will suffice for now. Cheers.

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