those are attribute references of a block. Since vla-fieldcode only works on Text and mtext i used Lee Macs fieldcode instead
https://www.lee-mac.com/fieldcode.html
It should work on Blocks Attributereferences as well now.
(defun c:change_prec (/ *error* acdoc undo-mark ss target index ename obj att field-string revised-string)
(defun *error* (msg)
(if undo-mark
(progn
(vl-catch-all-apply 'vla-EndUndoMark (list acdoc))
(setq undo-mark nil)
)
)
(if (and msg
(not (wcmatch (strcase msg) "*BREAK*,*CANCEL*,*EXIT*"))
)
(princ (strcat "\nError: " msg))
)
(princ)
)
(setq acdoc (vla-get-ActiveDocument (vlax-get-acad-object)))
(prompt "\nSelect text, MText, or attributed blocks: ")
(while (null (setq ss (ssget '((0 . "TEXT,MTEXT,INSERT")))))
(prompt "\nNo valid text, MText, or blocks selected.")
)
(initget 1 "0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 Current")
(setq target (getkword "\nTarget precision [0/1/2/3/4/5/6/7/8/9/10/11/12/13/14/15/16/Current]: "))
(vla-StartUndoMark acdoc)
(setq undo-mark T)
(repeat (setq index (sslength ss))
(setq index (1- index)
ename (ssname ss index)
obj (vlax-ename->vla-object ename)
)
(cond
;; Text or MText
((wcmatch (vla-get-ObjectName obj) "AcDbText,AcDbMText")
(setq field-string (vla-FieldCode obj))
(if (and field-string
(setq revised-string (replacePrecision field-string target))
)
(vla-put-TextString obj revised-string)
)
)
;; Block reference with editable attributes
((vlax-method-applicable-p obj 'GetAttributes)
(foreach att (vlax-invoke obj 'GetAttributes)
(setq field-string (LM:fieldcode (vlax-vla-object->ename att)))
(if (and field-string
(setq revised-string (replacePrecision field-string target))
)
(vla-put-TextString att revised-string)
)
)
)
)
)
(vla-EndUndoMark acdoc)
(setq undo-mark nil)
(vla-Regen acdoc acActiveViewport)
(princ)
)
(defun replacePrecision (fieldStr target / nbs prec_source return)
(setq nbs 0)
(cond
((vl-string-search "%<\\" fieldStr nbs)
(while nbs
(if (setq nbs (vl-string-search "%pr" fieldStr (setq tmp_nbs nbs)))
(setq
prec_source (itoa (atoi (substr fieldStr (+ nbs 4) 2)))
fieldStr
(vl-string-subst
(if (eq target "Current")
(strcat "%pr" (itoa (getvar "LUPREC")))
(strcat "%pr" target)
)
(strcat "%pr" prec_source)
fieldStr
tmp_nbs
)
nbs (1+ nbs)
)
)
)
(setq return fieldStr)
)
)
return
)
;; Field Code - Lee Mac
;; Returns the field expression associated with an entity
(defun LM:fieldcode ( ent / replacefield replaceobject fieldstring enx )
(defun replacefield ( str enx / ent fld pos )
(if (setq pos (vl-string-search "\\_FldIdx" (setq str (replaceobject str enx))))
(progn
(setq ent (assoc 360 enx)
fld (entget (cdr ent))
)
(strcat
(substr str 1 pos)
(replacefield (fieldstring fld) fld)
(replacefield (substr str (1+ (vl-string-search ">%" str pos))) (cdr (member ent enx)))
)
)
str
)
)
(defun replaceobject ( str enx / ent pos )
(if (setq pos (vl-string-search "ObjIdx" str))
(strcat
(substr str 1 (+ pos 5)) " "
(LM:ObjectID (vlax-ename->vla-object (cdr (setq ent (assoc 331 enx)))))
(replaceobject (substr str (1+ (vl-string-search ">%" str pos))) (cdr (member ent enx)))
)
str
)
)
(defun fieldstring ( enx / itm )
(if (setq itm (assoc 3 enx))
(strcat (cdr itm) (fieldstring (cdr (member itm enx))))
(cond ((cdr (assoc 2 enx))) (""))
)
)
(if (and (wcmatch (cdr (assoc 0 (setq enx (entget ent)))) "TEXT,MTEXT,ATTRIB,MULTILEADER,*DIMENSION")
(setq enx (cdr (assoc 360 enx)))
(setq enx (dictsearch enx "ACAD_FIELD"))
(setq enx (dictsearch (cdr (assoc -1 enx)) "TEXT"))
)
(replacefield (fieldstring enx) enx)
)
)
;; ObjectID - Lee Mac
;; Returns a string containing the ObjectID of a supplied VLA-Object
;; Compatible with 32-bit & 64-bit systems
(defun LM:ObjectID ( obj )
(eval
(list 'defun 'LM:ObjectID '( obj )
(if
(and
(vl-string-search "64" (getenv "PROCESSOR_ARCHITECTURE"))
(vlax-method-applicable-p (vla-get-utility (LM:acdoc)) 'getobjectidstring)
)
(list 'vla-getobjectidstring (vla-get-utility (LM:acdoc)) 'obj ':vlax-false)
'(itoa (vla-get-objectid obj))
)
)
)
(LM:ObjectID obj)
)
;; Active Document - Lee Mac
;; Returns the VLA Active Document Object
(defun LM:acdoc nil
(eval (list 'defun 'LM:acdoc 'nil (vla-get-activedocument (vlax-get-acad-object))))
(LM:acdoc)
)