TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: m4rdy on June 25, 2010, 01:02:58 AM
-
Perhaps this topic has been discussed before, but i couldn't find it.
I'll appreciate if anyone can help.
Thank's
m4rdy
-
Your question isn't clear. Please provide a more detailed description.
-
Hi Joe,
I have a routine to insert field code of object's areas. There area many objects. Some of them have inserted fields, others have not yet. Without selecting object's one by one, how to avoid inserting fields to object that have inserted field before.
Thank's
m4rdy
-
Hi,
AFAIK this information isn't stored in the entity, but the entity ObjectId is stored in the field code.
You can first select all mtexts and get the FielCode foreach mtext.
If the FieldCode matches "(%<\\_ObjId *>%).Area", store the ObjectId in a list.
Then select the polylines and remove from the selection those whose ObjectId is in the list
-
You can try to use the function _get-en-from-field
;;;Highlights primitives referenced object with a field
(defun C:FldViz ( / txt lst ss _get-en-from-field)
(defun _get-en-from-field (txt / dict field field_data lst lst1)
;_ Returns a list of entities belonging to the Field (s)
;_ txt - ename: TEXT MTEXT or Attrib [ENAME],
;_ like nentsel
(and
(setq dict (cdr (assoc 360 (entget txt)))) ;_Ename Dictionary
(setq dict
(cdr (assoc 360 (member '(3 . "ACAD_FIELD") (entget dict))))
) ;_Enable Field Dictionary
(setq dict (cdr (assoc 360 (member '(3 . "TEXT") (entget dict))))) ;_ Field Record
;_Sub Field Records
(setq field (mapcar 'cdr
(vl-remove-if
'(lambda (x) (/= (car x) 360))
(entget dict)
) ;_ end of vl-remove-if
) ;_ end of mapcar
) ;_ end of setq
(or (setq lst1 ;_direct link fields on the primitives
(apply 'append
(mapcar '(lambda (field_data)
(mapcar 'cdr
(vl-remove-if
'(lambda (x) (/= (car x) 331))
(entget field_data)
) ;_ end of vl-remove-if
) ;_ end of mapcar
) ;_ end of lambda
field
) ;_ end of mapcar
) ;_ end of apply
) ;_ end of setq
t
) ;_ end of or
(if (setq ;_nested reference fields on the primitives (the formulas in the fields)
lst (apply 'append
(mapcar '(lambda (field_data)
(mapcar 'cdr
(vl-remove-if
'(lambda (x) (/= (car x) 360))
(entget field_data)
) ;_ end of vl-remove-if
) ;_ end of mapcar
) ;_ end of lambda
field
) ;_ end of mapcar
) ;_ end of apply
) ;_ end of setq
(setq
lst (apply 'append
(mapcar '(lambda (field_data)
(mapcar 'cdr
(vl-remove-if
'(lambda (x) (/= (car x) 331))
(entget field_data)
) ;_ end of vl-remove-if
) ;_ end of mapcar
) ;_ end of lambda
lst
) ;_ end of mapcar
) ;_ end of apply
) ;_ end of setq
) ;_ end of if
) ;_ end of and
(append lst lst1)
)
(and
(setq txt (car(nentsel "\nSpecify an object with a field")))
(setq lst (_get-en-from-field txt))
(setq ss (ssadd ))
(mapcar '(lambda(x)(ssadd x ss)) lst)
(sssetfirst ss ss)
)
(setq ss nil)
(princ)
)
-
The vla-FieldCode function doesn't work with attributes.
If you need to get the field code text from an attibute, you can use the foloowing routine (works with nested fields in formulas):
;; gc:FieldCode (gile)
;; Returns the string from atext, mtext or attribute
;; with its field code
;;
;; Argument : the entity name (ENAME)
(defun gc:FieldCode (ent / foo elst xdict dict field str)
;;--------------------------------------------------------;;
(defun foo (field str / pos fldID objID)
(setq pos 0)
(if (setq pos (vl-string-search "\\_FldIdx " str pos))
(while (setq pos (vl-string-search "\\_FldIdx " str pos))
(setq fldId (entget (cdr (assoc 360 field)))
field (vl-remove (assoc 360 field) field)
str (strcat
(substr str 1 pos)
(if (setq objID (cdr (assoc 331 fldId)))
(vl-string-subst
(strcat "ObjId " (itoa (gc:EnameToObjectId objID)))
"ObjIdx"
(cdr (assoc 2 fldId))
)
(foo fldId (cdr (assoc 2 fldId)))
)
(substr str (1+ (vl-string-search ">%" str pos)))
)
)
)
str
)
)
;;--------------------------------------------------------;;
(setq elst (entget ent))
(if (and
(member (cdr (assoc 0 elst)) '("ATTRIB" "MTEXT" "TEXT"))
(setq xdict (cdr (assoc 360 elst)))
(setq dict (dictsearch xdict "ACAD_FIELD"))
(setq field (dictsearch (cdr (assoc -1 dict)) "TEXT"))
)
(setq str (foo field (cdr (assoc 2 field))))
)
)
;;============================================================;;
;; gc:EnameToObjectId (gile)
;; Returns the ObjectID from an ename
;;
;; Argument : an ename
(defun gc:EnameToObjectId (ename)
((lambda (str)
(hex2dec
(substr (vl-string-right-trim ">" str) (+ 3 (vl-string-search ":" str)))
)
)
(vl-princ-to-string ename)
)
)
;;============================================================;;
;; hex2dec (gile)
;; convert an hexadecimal into a décimal (int)
;;
;; Argument : un hexadedimal (string)
(defun hex2dec (s / r l n)
(setq r 0 l (vl-string->list (strcase s)))
(while (setq n (car l))
(setq l (cdr l)
r (+ (* r 16) (- n (if (<= n 57) 48 55)))
)
)
)
-
Have not tried and no idea if this could help, anyone have seen or inspect/scan the ACAD_FIELDLIST dictionary?... maybe
(and without reading any previous code posted)