CAD Forum - Database of tips, tricks and utilities for AutoCAD, Inventor and other Autodesk products [www.cadforum.cz]
CZ | EN | DE
Login or
registration
  Visitors: 8561
RSS channel - CAD tips RSS tips
RSS discussions

Discussion Discussion forum

 

HelpCAD discussion

 
CAD Forum - Homepage CAD discussion forum - ask any CAD-related questions here, share your CAD knowledge on AutoCAD, Inventor, Revit and other Autodesk software with your peers from all over the world. To start a new topic, choose an appropriate forum.

Please abide by the rules of this forum.

How to post questions: register or login, go to the specific forum and click the NEW TOPIC button.
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Topic ClosedAUTOAREA LISP

 Post Reply Post Reply Page  12>
Author
MK2015 View Drop Down
Newbie
Newbie


Joined: 14.May.2015
Location: Canada
Using: AutoCAD Map 3D
Status: Offline
Points: 7
Direct Link To This Post Topic: AUTOAREA LISP
    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
 
Back to Top
John Connor View Drop Down
Senior Member
Senior Member


Joined: 01.Feb.2011
Location: United States
Using: AutoCAD 2018
Status: Offline
Points: 7175
Direct Link To This Post 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>>

Back to Top
MK2015 View Drop Down
Newbie
Newbie


Joined: 14.May.2015
Location: Canada
Using: AutoCAD Map 3D
Status: Offline
Points: 7
Direct Link To This Post Posted: 14.May.2015 at 16:35
It freezes AutoCAD.
Back to Top
John Connor View Drop Down
Senior Member
Senior Member


Joined: 01.Feb.2011
Location: United States
Using: AutoCAD 2018
Status: Offline
Points: 7175
Direct Link To This Post Posted: 14.May.2015 at 16:50
I see what you mean as I just tried to use it in plain AutoCAD.


Edited by John Connor - 14.May.2015 at 16:58
"Humans have a strength that cannot be measured. This is John Connor. If you are reading this, you are the resistance."

<<AutoCAD 2015>>

Back to Top
Robert_D View Drop Down
Senior Member
Senior Member


Joined: 21.Oct.2013
Location: United States
Using: BricsCAD v21, AutoCAD2006
Status: Offline
Points: 207
Direct Link To This Post 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
Back to Top
MK2015 View Drop Down
Newbie
Newbie


Joined: 14.May.2015
Location: Canada
Using: AutoCAD Map 3D
Status: Offline
Points: 7
Direct Link To This Post 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.
 
 
Back to Top
Robert_D View Drop Down
Senior Member
Senior Member


Joined: 21.Oct.2013
Location: United States
Using: BricsCAD v21, AutoCAD2006
Status: Offline
Points: 207
Direct Link To This Post 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.
Back to Top
MK2015 View Drop Down
Newbie
Newbie


Joined: 14.May.2015
Location: Canada
Using: AutoCAD Map 3D
Status: Offline
Points: 7
Direct Link To This Post 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)
Back to Top
Robert_D View Drop Down
Senior Member
Senior Member


Joined: 21.Oct.2013
Location: United States
Using: BricsCAD v21, AutoCAD2006
Status: Offline
Points: 207
Direct Link To This Post 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)).
Back to Top
Robert_D View Drop Down
Senior Member
Senior Member


Joined: 21.Oct.2013
Location: United States
Using: BricsCAD v21, AutoCAD2006
Status: Offline
Points: 207
Direct Link To This Post 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
Back to Top

Related CAD tips:


 Post Reply Post Reply Page  12>
  Share Topic   

Forum Jump Forum Permissions View Drop Down



This page was generated in 0,496 seconds.