I'm working on a routine that will calcualte the area of an object and return that value in the form of a text string. The text string can be an existing text or can be added text. The more I use the nentsel function, the more really cool things I find about it. I have found that nentsel will find the actual area of a blocked or xref'd object no matter what the scale of the object is. That is so cool. No extra math involved. When I realized this, I wanted to be able to add the text to the block. So that's where I'm at. Has anybody done, or does anybody know of a way, without exploding and redefining the selected block, to embed text into a block? I'll post what I have so far.
;;select object
;;create object list
;;create object check list
;;select next object
;;check object against object list
(defun Mobj-selection ()
(while (setq nent
(nentsel
"\nSelect object to check the area of: "
)
)
(if (= alist nil)
(setq alist (append alist (list (car nent))))
(progn
(setq tlist alist)
(if (not (member (car nent) alist))
(setq alist
(append alist
(list (car nent))
)
)
(progn
(prompt
"\nObject selected previously, will not be added to selection."
)
(setq alist tlist)
)
)
)
)
)
)
(defun obj-list-creater ()
(foreach item alist
(setq nlist
(append nlist
(list (vlax-ename->vla-object item))
)
)
)
(foreach obj nlist
(setq area (vla-get-area obj))
(setq oarea (+ oarea area))
(setq sqft (/ oarea 144))
)
)
(defun Str-selected-obj ()
(setq sqfttext (strcat (rtos sqft 2 0) " SQ. FT."))
(initget "Newtext")
(setq tent
(nentsel
"\nSelect text object to add area to or [New text]: "
)
)
)
(defun Str-CmdLine-PassBack ()
(princ (strcat
"\nArea of selected objects are:\n"
(rtos oarea 2 2)
" square inches.\n"
(rtos sqft 2 2)
" square feet."
)
)
)
(defun Str-obj->String ()
(defun TextAdd ()
(vla-addText Model sqfttext (vlax-3d-point (cadr tent)) 3.0)
)
(defun typeobj (val ent)
(cdr (assoc val (entget (car ent))))
)
(cond ((and (= (type tent) 'LIST)
(= (length tent) 2)
(or (= (typeobj 0 tent) "TEXT")
(= (typeobj 0 tent) "MTEXT")
(= (typeobj 0 tent) "ATTRIB")
)
)
(vla-put-textString
(vlax-ename->vla-object (car tent))
sqfttext
)
(if (= (length tent) 4)
(vla-regen $acad acAllViewports)
)
)
((= tent nil)
(setq tent (grread (getvar 'lastpoint)))
(TextAdd)
)
((= tent "Newtext")
(setq tent
(getpoint "\nSelect point for placement of text: ")
)
(TextAdd)
)
)
)
;;;-----------------------------------------------------------------------------;
;;; Add Text to Selected Area Object ;
;;;-----------------------------------------------------------------------------;
;;; ver. 1.0 ;
;;; Routine calculates area by objects and places or replaces text object info ;
;;;-----------------------------------------------------------------------------;
;;; todo: Get layer information of object and put text on that layer. ;
;;; Separate single object selection and multiple object selection ;
;;; and make repeatable single selection. ;
;;; Find a way to embed text into a block or xref. ;
;;;_____________________________________________________________________________;
(defun c:ara (/ alist tlist nlist oarea nent area sqft tent Model)
(setq alist nil
tlist nil
nlist nil
oarea 0
Model (vla-get-modelspace
(vla-get-activedocument
(vlax-get-acad-object)
)
)
)
(Mobj-selection)
(obj-list-creater)
(Str-selected-obj)
(Str-obj->String)
(Str-CmdLine-PassBack)
(princ)
)