Author Topic: Looking for a way to test for an Attrib Value in a drawing  (Read 2305 times)

0 Members and 1 Guest are viewing this topic.

deegeecees

  • Guest
Looking for a way to test for an Attrib Value in a drawing
« on: April 30, 2004, 03:59:03 PM »
I have a drawing with a block called "jpole", and it contains an attribute with a Tag of "Number", with a value of "9992". I need to test for this with a Lisp expression. Anyone got an answer?

I've tried this:

(setq tester1 (SSGET "X" (LIST (CONS 0 "ATTRIB") (CONS 2 "NUMBER") (CONS 1 "9992"))))

Mark

  • Custom Title
  • Seagull
  • Posts: 28753
Looking for a way to test for an Attrib Value in a drawing
« Reply #1 on: April 30, 2004, 05:24:23 PM »
quick-n-dirty
Code: [Select]

;;; FUNCTION
;;; returns a list of attributes and values. i.e.
;;; (("WHAT" . "Desk") ("WHO" . "Mark"))
;;;
;;; ARGUMENTS
;;; vla-object (block object)
;;;
;;; USAGE
;;; (setq ent (car (entsel "\nPick a Block...")))
;;; (setq Blk (vlax-ename->vla-object ent))
;;; (setq lst (MST-attribute_list Blk))
;;;
;;;
;;; PLATFORMS
;;; 2000+
;;;
;;; AUTHOR
;;; Copyright© 2002 Mark S. Thomas
;;; mark.thomas@theswamp.org
;;;
;;; VERSION
;;; 1.0 Fri Aug 16, 2002
;;; 1.1 Wed Feb 12, 2003 19:30:11 changed function name
(defun MST-attribute_list (Obj / attribs attrib-list attribute-list)

  (if (= (type Obj) 'VLA-OBJECT)
    (if (= (vlax-get-property Obj 'ObjectName) "AcDbBlockReference")
      (if (= (vlax-get-property Obj 'HasAttributes) :vlax-true)
        (progn
          (setq attribs
                (vla-GetAttributes Obj)
                attrib-list
                (vlax-safearray->list (vlax-variant-value attribs))
                ); setq

          (foreach X attrib-list
                   (setq attribute-list
                         (append
                           (list
                             (cons
                               (vlax-get-property X 'TagString)
                               (vlax-get-property X 'TextString)
                               )
                             )
                           attribute-list)
                         )
                   ); foreach
          ); progn
        )
      )
    )
  attribute-list
  ); defun

Code: [Select]

(defun find-9992 (/ ss cntr obj lst blk_lst)
  (setq ss   (ssget "_x" '((0 . "INSERT") (2 . "jpole")))
        cntr 0
        )

  (repeat (sslength ss)
    (setq obj (vlax-ename->vla-object (ssname ss cntr))
          lst (MST-attribute_list obj)
          )
    (if (= (cdr (assoc "NUMBER" lst)) "9992"); case sensitive 'assoc'
      (setq blk_lst (cons (vlax-vla-object->ename obj) blk_lst))
      )
    (setq cntr (1+ cntr))
    )
  blk_lst
  )


Code: [Select]

(setq blk-ent-lst (find-9992))
TheSwamp.org  (serving the CAD community since 2003)