Print Page | Close Window

AUTOAREA LISP

Printed From: CAD Forum
Category: EN
Forum Name: CAD - general
Forum Description: General discussion about CAD, formats, standards, management, licensing, networking, harware, other CAD applications
URL: https://www.cadforum.cz/forum_en/forum_posts.asp?TID=11169
Printed Date: 22.May.2026 at 10:25


Topic: AUTOAREA LISP
Posted By: MK2015
Subject: AUTOAREA LISP
Date Posted: 14.May.2015 at 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
 



Replies:
Posted By: John Connor
Date Posted: 14.May.2015 at 11:59
What kind of error are you getting?


-------------
"Humans have a strength that cannot be measured. This is John Connor. If you are reading this, you are the resistance."

<<AutoCAD 2015>>



Posted By: MK2015
Date Posted: 14.May.2015 at 16:35
It freezes AutoCAD.


Posted By: John Connor
Date Posted: 14.May.2015 at 16:50
I see what you mean as I just tried to use it in plain AutoCAD.


-------------
"Humans have a strength that cannot be measured. This is John Connor. If you are reading this, you are the resistance."

<<AutoCAD 2015>>



Posted By: Robert_D
Date Posted: 14.May.2015 at 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


Posted By: MK2015
Date Posted: 14.May.2015 at 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.
 
 


Posted By: Robert_D
Date Posted: 14.May.2015 at 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.


Posted By: MK2015
Date Posted: 14.May.2015 at 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)


Posted By: Robert_D
Date Posted: 14.May.2015 at 21:00
Originally posted by MK2015 MK2015 wrote:

1).How do I go to 2 decimal places?  But again my old one was ideal as I also require area in hectares...
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)).


Posted By: Robert_D
Date Posted: 14.May.2015 at 21:11
Also, lee-mac has a few routines which may (?) be of interest:
http://www.lee-mac.com/areastofield.html
http://www.lee-mac.com/arealabel.html
http://www.lee-mac.com/areafieldtoattribute.html


Posted By: MK2015
Date Posted: 15.May.2015 at 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.



Print Page | Close Window