To save processing all attributes, I would sometimes use this:
;;----------------=={ Get Attribute Value }==-----------------;;
;; ;;
;; Returns the attribute value associated with the specified ;;
;; tag, within the supplied block, if present. ;;
;;------------------------------------------------------------;;
;; Author: Lee McDonnell, 2010 ;;
;; ;;
;; Copyright © 2010 by Lee McDonnell, All Rights Reserved. ;;
;; Contact: Lee Mac @ TheSwamp.org, CADTutor.net ;;
;;------------------------------------------------------------;;
;; Arguments: ;;
;; block - VLA Block Reference Object ;;
;; tag - Attribute TagString ;;
;;------------------------------------------------------------;;
;; Returns: Attribute TextString, else nil ;;
;;------------------------------------------------------------;;
(defun LM:GetAttributeValue ( block tag )
;; © Lee Mac 2010
(vl-some
(function
(lambda ( attrib )
(if (eq tag (vla-get-Tagstring attrib))
(vla-get-TextString attrib)
)
)
)
(vlax-invoke block 'GetAttributes)
)
)
Example:
(defun c:test ( / ent )
(if (setq ent (car (entsel "\nSelect Attributed Block: ")))
(princ
(LM:GetAttributeValue
(vlax-ename->vla-object ent) (strcase (getstring "\nSpecify Tag String: "))
)
)
)
(princ)
)