PDA

View Full Version : LISP Routine that works with AREA command



Paul.C.Rasmussen
2004-09-09, 04:22 PM
Does anyone know of a LISP routine that will take the AREA of a a CLOSED POLYLINE and create text on the drawing in an ATTRIBUTE block? Cost accounting would like me to tell them the SQUARE FOOTAGE of different rooms in our company's buildings so they can allocate costs by department based on the area that they occupy. I assume that many other companies do this too. Does anyone know of someone who has already created this?

Jeff_M
2004-09-09, 06:12 PM
Here's a routine I use that adds the square footage as Text. It wouldn't be too difficult to modify it to use an attributed block though.



;; =================================================
;; 2002 By Luis Esquivel
;; put the area in sq-ft of selected closed areas...
;; modified 11/22/03 by Jeff Mishler to allow use within
;; PS Viewport and to accept a Polyline that was created
;; by selecting the startpoint as the endpoint, technically
;; it is closed but the closed property isn't set.
;;
;; Command: PUTAREA

;;;(addtext <string> <point> <real>)
(defun addtext (textstring insertionpoint height / aa)
(vl-load-com)
(setq aa (vla-get-activedocument (vlax-get-acad-object)))
(vla-addtext
(if (= 1 (vla-get-activespace aa))
(vla-get-modelspace aa)
(if (= (vla-get-mspace aa) :vlax-true)
(vla-get-modelspace aa)
(vla-get-paperspace aa)
)
)
textstring
(vlax-3d-point insertionpoint)
height)
)

(defun add-comma (txt / strl cont1 lth cont txt1)
(setq strl (strlen txt)
cont1 1
txt1 "")
(while (and (/= (substr txt cont1 1) ".") (<= cont1 strl))
(setq cont1 (1+ cont1)))
(setq lth (1- cont1)
cont1 1
cont (1- lth))
(if (> lth 3)
(progn
(while (< cont1 lth)
(setq let (substr txt cont1 1)
txt1 (strcat txt1 let))
(if (and (zerop (rem cont 3)) (eq (type (read let)) 'INT))
(setq txt1 (strcat txt1 ",")))
(setq cont (1- cont)
cont1 (1+ cont1)))
(while (<= cont1 strl)
(setq txt1 (strcat txt1 (substr txt cont1 1))
cont1 (1+ cont1)))
txt1)
txt))

(defun get-last-coord (obj / COORDS LAST_COORD)
(setq coords (vla-get-coordinates obj)
coords (vlax-safearray->list (vlax-variant-value coords))
coords (reverse coords)
last_coord (list (cadr coords)(car coords)
)
)
last_coord
)

(defun C:PUTAREA (/ ent vla_obj pt objname vla_text aa)
(while (setq ent (entsel "\nSelect closed object: "))
(setq vla_obj (vlax-ename->vla-object (car ent))
objname (vla-get-objectname vla_obj))
(if
(vlax-property-available-p vla_obj 'area)
(progn
(if
(or
(= "AcDbCircle" objname)
(and (wcmatch (vla-get-objectname vla_obj) "*Polyline")
(or (= :vlax-true (vla-get-closed vla_obj))
(equal (vlax-safearray->list
(vlax-variant-value
(vla-get-coordinate vla_obj '0)))
(get-last-coord vla_obj)
0.001)
)
)
)
(progn
(if (setq pt (getpoint "\nPick text placement: "))
(progn
(setq vla_text
(addtext
(strcat
(add-comma
(rtos
(vla-get-area vla_obj)
2
0))
" S.F.")
pt
(getvar "textsize")))

;; alignment to left
(vla-put-alignment vla_text acAlignmentCenter)

(vla-put-textalignmentpoint
vla_text
(vlax-3d-point pt))

;; use current textstyle
(vla-put-stylename
vla_text
(vla-get-name
(vla-get-activetextstyle
(setq aa (vla-get-activedocument
(vlax-get-acad-object)))))))))
(prompt "\nNot a closed object. ")
))))
(princ))
(princ)


HTH,
Jeff

Mike.Perry
2004-09-09, 06:25 PM
Hi

If you're using AutoCAD 2005 you might want to take a look at using FIELDS instead, the following threads discuss that topic -

Formatting for Precision in Fields (http://forums.augi.com/showthread.php?t=5991&highlight=Polyline+Area)

Fields again (http://forums.augi.com/showthread.php?t=7695&highlight=Polyline+Area)

+

http://intervision.hjem.wanadoo.dk/ -> AutoLISP Archive (from the left hand side menu) -> Roomarea.lsp & Room_no.dwg

http://www.llpsite.com/freeware.htm -> Drawing Aids (near the bottom) -> areacalc.zip

Have a good one, Mike

Paul.C.Rasmussen
2004-09-09, 08:16 PM
Thanks a bunch, Mike!
I'm still with AutoCAD 2004. I'll try out the other two routines.
Thanks again,
Paul

Paul.C.Rasmussen
2004-09-09, 08:33 PM
Jeff, I'm not yet savy enought to modify (or even understand) AutoLISP code. Thanks for the info. Perhaps someone else will be able to modify it.
What does "HTH" mean?
Paul

Jeff_M
2004-09-09, 09:40 PM
HTH = Hope That Helps

Paul, You don't need to modify it at all if you just want to label the square footages. Just load it and run it with the "PUTAREA" command. This code is set-up to use feet. If your base units are inches then the code will need to be adjusted for that.

If you absolutely need the format to be in block form, if you provide me with the block name & attribute tag string (the actual block drawing would be helpful) I will modify the code as needed.

Prasadaxiom
2015-10-05, 11:37 AM
Can anyone give a lisp command to get the area in Square ft instead of Square Meter in Area command output?

alongrey373743
2016-01-03, 07:52 PM
Does anyone know of a LISP routine that will take the AREA of a a CLOSED POLYLINE and create text on the drawing in an ATTRIBUTE block? Cost accounting would like me to tell them the SQUARE FOOTAGE of different rooms in our company's buildings so they can allocate costs by department based on the area that they occupy. I assume that many other companies do this too. Does anyone know of someone who has already created this?

Non Free (http://www.kimprojects.com/product/measure-area-autocad/) Plug-in us$20 (AreaMeasure By KIM) will cover any unit(drawing unit and output you desire and will get the job done quickly.