Here is my version, using a Field:
;; Link Dimension to Attribute - Lee Mac
;; Prompts for selection of a Dimension and references the Dimension
;; value using a Field located in a selected block attribute.
(defun c:Dim2Att ( / *error* ad at el en g1 g2 gr ms ob p1 st )
(defun *error* ( msg )
(if en (redraw en 4))
(if ad (vla-endundomark ad))
(if (not (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*"))
(princ (strcat "\nError: " msg))
)
(redraw) (princ)
)
(while
(progn (setvar 'ERRNO 0) (setq en (car (entsel "\nSelect Dimension to Link: ")))
(cond
( (= 7 (getvar 'ERRNO))
(princ "\nMissed, try again.")
)
( (eq 'ENAME (type en))
(if (not (wcmatch (cdr (assoc 0 (entget en))) "*DIMENSION"))
(princ "\nObject is not a Dimension.")
)
)
)
)
)
(if en
(progn
(setq ad (vla-get-activedocument (vlax-get-acad-object))
el (entget en)
p1 (trans (cdr (assoc 11 el)) en 1)
ob (vlax-ename->vla-object en)
st (strcat
"%<\\AcObjProp Object(%<\\_ObjId "
(if
(and
(vl-string-search "64" (getenv "PROCESSOR_ARCHITECTURE"))
(vlax-method-applicable-p (vla-get-utility ad) 'getobjectidstring)
)
(vla-getobjectidstring (vla-get-utility ad) ob :vlax-false)
(itoa (vla-get-objectid ob))
)
(if (eq "" (cdr (assoc 1 el)))
">%).Measurement \\f \"%lu6\">%"
">%).TextOverride>%"
)
)
)
(vla-startundomark ad)
(redraw en 3)
(princ (setq ms "\nSelect Attribute to Link to Dimension: "))
(while
(progn
(setq gr (grread t 13 2)
g1 (car gr)
g2 (cadr gr)
)
(cond
( (= 5 g1)
(redraw)
(grdraw p1 g2 3 1)
t
)
( (= 3 g1)
(redraw)
(if (setq at (car (nentselp g2)))
(if (eq "ATTRIB" (cdr (assoc 0 (entget at))))
(progn
(vla-put-textstring (vlax-ename->vla-object at) st)
(vl-cmdf "_.updatefield" at "")
(princ ms)
)
(princ (strcat "\nObject is not an Attribute." ms))
)
(princ (strcat "\nMissed, try again." ms))
)
t
)
)
)
)
(redraw en 4)
(redraw)
(vla-endundomark ad)
)
)
(princ)
)
(vl-load-com) (princ)