Display full version of the post: AUTOAREA LISP

MK2015
14.05.2015, 00:31

Can anyone make this work in AutoCAD Map3D 2015?(It works fine in AutoCAD Map3D 2013 but we have upgraded to 2015)  AUTOAREA.LSP: ;;This program will calculate the area of irregular polygons;;by picking an area inside the polygon.(defun C:AUTOAREA (/ ar en n num pt ss1)   (if (not "acadapp.exp")(xload "acadapp.exp"))   (setq n 0)   (setq ss1 (ssadd))   (while (setq pt (getpoint "\nSelect internal point:"))      (bpoly pt) ;;ADS function      (setq ss1 (ssadd (entlast) ss1))   );;while   (setq num (sslength ss1))   (command ".area" "a" "e")   (while (/= num n)      (setq en (ssname ss1 n))      (command en)      (setq n (1+ n))   );;while   (command "" "")   (command "erase" ss1 "")   (command "redraw")   (princ "\nThe area of the polygon in hectares is: ")   (princ (cvunit (setq ar (getvar "AREA")) "SQ METER" "HECTARE"))   (princ "\nThe area of the polygon in acres is: ")   (princ (cvunit (setq ar (getvar "AREA")) "SQ METER" "ACRE"))   (setq ss nil)   (prin1) );;end autoarea.lsp 

John Connor
14.05.2015, 11:59
What kind of error are you getting?

MK2015
14.05.2015, 16:35

It freezes AutoCAD.

John Connor
14.05.2015, 16:50
I see what you mean as I just tried to use it in plain AutoCAD.

John Connor2015-05-14 16:58:33

Robert_D
14.05.2015, 16:53
A similar AREA2.LSP you can try:;;;  places area at specified point(defun c:area2 (/ olderr en el hlt areatxt pt1)  (setq olderr *error*)  (defun *error* (str)    (if    (= str "Function cancelled")      (princ)      (princ (strcat "Error: " str))            )                    ;if    (if hlt      (redraw (car en) 4))    (setvar "cmdecho" 1)    (setq *error* olderr)    )                    ;defun error  (setq en 1)  (setvar "cmdecho" 0)  (while en    (while (not                ;make sure user selects an object         (setq en (entsel "\nSelect object or [Escape] to quit "))         )     )    (setq hlt 1)    (redraw (car en) 3)    (setq el (entget (car en)))    (if    (or      (= (cdr (assoc 0 el)) "LWPOLYLINE")      (= (cdr (assoc 0 el)) "CIRCLE")      (= (cdr (assoc 0 el)) "ELLIPSE")      );or      (progn    (command ".area" "o" en)    (setq areatxt (/ (getvar "area") 144))    (while (not            ;make sure user selects a point         (setq pt1 (getpoint "\nSelect point for text "))         )     );while    (if (not (tblsearch "layer" "SQ-FT"))      (command ".-layer" "m" "SQ-FT" "c" "7" "SQ-FT" ""))    (setvar "clayer" "SQ-FT")        (setq el (subst '(8 . "SQ-FT") (assoc 8 el) el))        (entmod el)        (setvar "textstyle" "standard")        (if (/= (cdr (assoc 40 (tblsearch "style" "standard"))) 0)      (command ".text" "j" "mc" pt1 0 (strcat (rtos areatxt 2 1) " SF"))          (command ".text" pt1 8.0 0 (strcat (rtos areatxt 2 1) " SF"))          );if    );progn      );if    (setq hlt nil)    (redraw (car en) 4)    );while  (setvar "cmdecho" 1)  (setq *error* olderr)  (princ)  )                    ;end of function

MK2015
14.05.2015, 17:59

Robert:Thanks, but this one doesn't work for us mainly for these 2 reasons:- I need the area in Acres and Hectares, not square feet- This requires a closed polyline and we are always dealing with cadastral mapping which is made up of lines or polylines. I realize I could use the boundary command, but this creates an extra step.  

Robert_D
14.05.2015, 18:21
1) You could modify the routine. You'll notice (getvar "area") 144)) where it divides the default inches and divides by 144 for ft2.2) I would think all routines would require a closed polyline.

MK2015
14.05.2015, 19:52

1) Yes, thanks. How do I go to 2 decimal places?  But again my old one was ideal as I also require area in hectares.2.) My old Autoarea.lsp doesn't require a closed polyline and that's what makes it so convenient. (It creates a temporary closed polyline by itself and then deletes it)

Robert_D
14.05.2015, 21:00
[QUOTE=MK2015]
1).How do I go to 2 decimal places?  But again my old one was ideal as I also require area in hectares...[/QUOTE]Hmm, don't know about the decimal places, may play around if I get time.Hectares display correctly if you replace (getvar "area") 144)) with (getvar "area") 15500031.0001)).

Robert_D
14.05.2015, 21:11
Also, lee-mac has a few routines which may (?) be of interest:http://www.lee-mac.com/areastofield.htmlhttp://www.lee-mac.com/arealabel.htmlhttp://www.lee-mac.com/areafieldtoattribute.html

MK2015
15.05.2015, 18:23

Thanks Robert. But ideally it would be nice if I could get my old routine to work. You see I need the area in acres and hectares simultaneously. And it's also very convenient because it does not require a closed polyline.