|Function Syntax||(LM:fieldobjects <ent>)|
|ent||EName||Entity containing field expression (Text / MText / Attribute)|
|List||List of entities referenced by field expression, else nil|
When supplied with the entity name of an annotation object containing a field expression (a Text, MText or Attribute entity), this function will return a list of entities referenced by the field expression; or nil if the field does not reference any objects (such as a date/time field, for example).
The function will also work for nested field expressions, such as Property Fields nested within Expression Fields, as created by my Areas to Field program, returning all entities referenced by the Property Fields.
;; Field Objects - Lee Mac ;; Returns a list of entities referenced by a supplied field ;; ent - [ent] Entity containing field (Text / MText / Attribute) ;; Returns: [lst] List of entities referenced by Field, else nil (defun LM:fieldobjects ( ent / _getfieldobjects ) (defun _getfieldobjects ( a ) (apply 'append (mapcar '(lambda ( a ) (if (= 360 (car a)) (_getfieldobjects (cdr a)) (if (= 331 (car a)) (list (cdr a))) ) ) (entget a) ) ) ) (if (and (wcmatch (cdr (assoc 0 (setq ent (entget ent)))) "TEXT,MTEXT,ATTRIB") (setq ent (cdr (assoc 360 ent))) (setq ent (dictsearch ent "acad_field")) (setq ent (dictsearch (cdr (assoc -1 ent)) "text")) ) (_getfieldobjects (cdr (assoc -1 ent))) ) )
The following example will prompt the user to select an object containing a field expression (Text, MText or Attribute object), and will proceed to highlight the objects referenced by the field (perform a REGEN to remove the highlighting).
(defun c:test ( / ent lst ) (while (progn (setvar 'errno 0) (setq ent (car (nentsel "\nSelect field: "))) (cond ( (= 7 (getvar 'errno)) (princ "\nMissed, try again.") ) ( (null ent) nil) ( (setq lst (LM:fieldobjects ent)) (foreach ent lst (redraw ent 3)) ) ( (princ "\nSelected object is not a field, or field doesn't reference any objects.")) ) ) ) (princ) )