Someone on the Adesk Ng was asking about this, and I thought it might be fun to see what I could find out. I don't use fields, and do not pretend to know what I did, but it works.
I created a field linked to a text object. I then ran this code, and selected the field object just created, and it worked in changing the association of the existing field from the text object to the layout it is in. If you change the name of the layout it will change the field.
It is a starting point, so use it as you like.
(progn
(setq Sel (entsel "\n Select object to change field value: "))
(setq Obj (vlax-ename->vla-object (car Sel)))
(if
(and
(equal (vla-get-HasExtensionDictionary Obj) :vlax-true)
(setq Dict (vla-GetExtensionDictionary Obj))
(not
(vl-catch-all-error-p
(setq FDict
(vl-catch-all-apply
'vla-Item
(list
Dict
"ACAD_FIELD"
)
)
)
)
)
)
(vlax-for tempObj FDict
(setq tempData (entget (vlax-vla-object->ename tempObj)))
[color=red]; here I thought you needed to change this to layout, but you do not.[/color]
;(setq tempData (subst (cons 1 "_layout") (assoc 1 tempData) tempData))
;(setq tempData (subst (cons 1 "_text") (assoc 1 tempData) tempData))
;(entmod tempData)
(setq tempData (entget (cdr (assoc 360 tempData))))
(setq tempData
(subst
'(2 . "\\AcObjProp Object(%<\\_ObjIdx 0>%).Name")
(assoc 2 tempData)
tempData
)
)
(setq tempData
(subst
(cons
330
(vlax-vla-object->ename
(setq ActLo
(vla-get-ActiveLayout
(vla-get-ActiveDocument
(vlax-get-Acad-Object)
)
)
)
)
)
(assoc 330 (reverse tempData))
tempData
)
)
(setq tempList
(vl-remove-if-not
'(lambda (x) (equal (car x) 1))
tempData
)
)
(setq tempData
(subst
'(1 . "Name")
(nth 1 tempList)
tempData
)
)
(setq tempData
(subst
(cons 1 (vla-get-Name ActLo))
(nth 2 tempList)
tempData
)
)
(setq tempData
(subst
(cons 301 (vla-get-Name ActLo))
(assoc 301 tempData)
tempData
)
)
(entmod tempData)
)
)
)