Lee
Lee
;; ;;
;; This program allows a user to populate a selected attribute with ;;
;; a Field Expression referencing the area, or sum of areas, of one ;;
;; or more objects. ;;
;; ;;
;; Upon issuing the command syntax 'A2A' the user is prompted to ;;
;; make a selection of objects for which to retrieve the area; if ;;
;; more than one object is selected, the cumulative area for all ;;
;; objects will be displayed by the resultant Field Expression. ;;
;; ;;
;; Following object selection, the user is then prompted to select ;;
;; either an attributed block or an attribute in which to house the ;;
;; Field Expression. The Field will display the sum of the areas of ;;
;; the selected objects, formatted using the Field formatting code ;;
;; specified at the top of the program. ;;
;;----------------------------------------------------------------------;;
;; Author: Lee Mac, Copyright � 2013 - www.lee-mac.com ;;
;;----------------------------------------------------------------------;;
;; Version 1.2 - 2016-01-16 ;;
;;----------------------------------------------------------------------;;
(defun c:a2a ( / *error* ats att enx fmt idx inc lst sel tag tmp )
(if
(and (setq sel (ssget '((0 .
"ARC,CIRCLE,ELLIPSE,HATCH,*POLYLINE,REGION,SPLINE"))))
(progn
(while
(progn (setvar 'errno 0) (setq ats (nentsel "\nSelect attribute
or attributed block: "))
(cond
( (= 7 (getvar 'errno))
(princ "\nMissed, try again.")
)
( (null ats)
nil
)
( (and (= "ATTRIB" (cdr (assoc 0 (setq enx (entget
(car ats))))))
(/= 'str (type tag))
)
(setq att (vlax-ename->vla-object (car ats)))
nil
)
( (and
(or
(and (= "ATTRIB" (cdr (assoc 0 enx)))
(setq tmp (cdr (assoc 330 enx)))
)
(and (setq tmp (last (cadddr ats)))
(= "INSERT" (cdr (assoc 0 (entget
tmp))))
)
)
(setq tmp (vlax-invoke (vlax-ename->vla-object
tmp) 'getattributes))
)
(not
(or
(and (= 'str (type tag))
(setq idx (vl-position (strcase tag)
(mapcar 'vla-get-tagstring tmp)))
(setq att (nth idx tmp))
)
(and (not (cdr tmp))
(setq att (car tmp))
)
(and (setq idx (LM:listbox "Choose
Attribute" (mapcar 'vla-get-tagstring tmp) 2))
(setq att (nth (car idx) tmp))
)
)
)
)
( (princ "\nThe selected object is not an attribute
or attributed block."))
)
)
)
(= 'vla-object (type att))
)
)
(progn
(LM:startundo (LM:acdoc))
(if (= 1 (sslength sel))
(vla-put-textstring att
(strcat
"%<\\AcObjProp Object(%<\\_ObjId "
(LM:objectid (vlax-ename->vla-object (ssname sel 0)))
">%).Area \\f \"" fmt "\">%"
)
)
(progn
(repeat (setq inc (sslength sel))
(setq lst
(vl-list*
"%<\\AcObjProp Object(%<\\_ObjId "
(LM:objectid (vlax-ename->vla-object (ssname sel
(setq inc (1- inc)))))
">%).Area>%" " + "
lst
)
)
)
(vla-put-textstring att
(strcat
"%<\\AcExpr "
(apply 'strcat (reverse (cdr (reverse lst))))
" \\f \"" fmt "\">%"
)
)
)
)
(vl-cmdf "_.updatefield" (vlax-vla-object->ename att) "")
(LM:endundo (LM:acdoc))
)
)
(princ)
)
;;----------------------------------------------------------------------;;
(vl-load-com)
(princ
(strcat
"\n:: Areas2Attribute.lsp | Version 1.2 | \\U+00A9 Lee Mac "
(menucmd "m=$(edtime,0,yyyy)")
" www.lee-mac.com ::"
"\n:: Type \"A2A\" to Invoke ::"
)
)
(princ)
;;----------------------------------------------------------------------;;
;; End of File ;;
;;----------------------------------------------------------------------;;