Step though Attributes to find Certain tags

Step though Attributes to find Certain tags

Anonymous
Not applicable
814 Views
4 Replies
Message 1 of 5

Step though Attributes to find Certain tags

Anonymous
Not applicable

Hey guys,

 

I've never had to do this before and I thought it may be simple but alas I need help.

 

I have a border that has several attributes, I need to step through those attributes and make a list of only the attributes with certain tags.

 

For instance In the border named Stooges there are attributes name Moe, Bill, Larry, Fred, Curly, Steve etc.

 

I need to make a list that only contains Moe, Larry and Curly.

 

How Do I accomplish this?

 

I've been able to select the border using

 

(defun c:STOOGE ()
  (setq Border (ssget "_X" (list (cons 0 "insert")(cons 2 "Stooges"))))
)

 Thanks a Million

 

0 Likes
Accepted solutions (1)
815 Views
4 Replies
Replies (4)
Message 2 of 5

devitg
Advisor
Advisor

It is not mine, I grab it somewhere 

 

 

(DEFUN G-ATT-LIST  (ENT-OBJBLK
                    /
                    ;;lst
                    )
  (IF (= (TYPE ENT-OBJBLK) 'ENAME)
    (SETQ OBJBLK (VLAX-ENAME->VLA-OBJECT ENT-OBJBLK))
    (SETQ OBJBLK ENT-OBJBLK)
    )
  (COND
    ((NOT OBJBLK))
    ((/= (VLA-GET-HASATTRIBUTES OBJBLK) :VLAX-TRUE))
    ((VL-CATCH-ALL-ERROR-P
       (SETQ LST (VL-CATCH-ALL-APPLY
                   'VLAX-SAFEARRAY->LIST
                   (LIST (VLAX-VARIANT-VALUE (VLA-GETATTRIBUTES OBJBLK))))))
     (SETQ LST NIL)
     )
    ) ;_c.cond 
  LST
  ) ;_c.defun 

 

 

It return  the attribute objects 

 

Then you have to look for the tags , and it´s string . 

 

 

 

 

 

0 Likes
Message 3 of 5

hmsilva
Mentor
Mentor
Accepted solution

As a starting point...

 

;; test if Stooges exist in current tab
(if (setq Border (ssget "_X"
                        (list '(0 . "insert")
                              '(2 . "Stooges")
                              ;; has attributes
                              '(66 . 1)
                              ;; only in the current tab
                              (cons 410 (getvar 'CTAB))
                        )
                 )
    )
   ;; if exists
   (progn
      ;; set 'enm' with INSERT's ename
      (setq enm (ssname Border 0))
      ;; set 'obj' with the ename sored in 'enm' as a VLA object
      (setq obj (vlax-ename->vla-object enm))
      ;; set 'atts' as a list with all attributs as VLA objects
      (setq atts (vlax-invoke obj "GetAttributes"))
      ;; process each attribute
      (foreach att atts
         ;; test if TagString is one we need
         (if (wcmatch (vla-get-tagstring att) "Moe,Larry,Curly")
            ;; if true, store in 'lst' the Tag and the Value
            (setq lst (cons (cons (vla-get-tagstring att) (vla-get-textstring att)) lst))
         )
      )
   )
)

 

Hope this helps,
Henrique

EESignature

0 Likes
Message 4 of 5

Anonymous
Not applicable

That did it! thank you very much.

0 Likes
Message 5 of 5

hmsilva
Mentor
Mentor
You’re welcome!

Glad I could help
Henrique

EESignature

0 Likes