Download Free Lisp to write area of polylines in AutoCAD

Download Free Lisp to Display the Area of Polylines in AutoCAD

Lisp to Display the Area of Polylines in AutoCAD 

FreeCADTipsAndTricks is back this week with another excellent lisp routine for AutoCAD.  Areaon.lsp is a LISP routine that will display the entire area of a selection set of objects. 

This can be supportive if you want to compute the total area of multiple closed polylines, for example.  

Start by loading the LISP file, Appload the lisp file by entering AP in the AutoCAD command line. 

 “Command: AP APPLOAD AREARON.LSP successfully loaded.” Will be displayed in the command line.

The command for starting the lisp file is “AreaOn.”

I Recommend You To Read:

100+ Cad blocks Sports and Gym equipment dwg AutoCAD drawing free Download

Stairs and Outdoor Design sample AutoCAD drawings and CAD blocks

AutoCAD Vehicles Cars, Airplane, Ships, and Boats CAD Blocks Free Download

The function of AutoLISP: 

  1. It will first request you specify the scale of the drawing (e.g., if you type 1, 10 or 20, etc., it’ll change the text size consequently).“ENTER SCALE (1.00): 1 “ 
  2. Enter the number of decimal places you need for figures “HOW MANY DECIMAL PLACES?: (3.00):”
  3. Finally, it asks to select the polylines. “SELECT CLOSED POLYLINES:” Make sure all the objects are polylines and are closed. 
  4. After the selection of polylines, hit enter. 

If you need to calculate the area of Polylines, you can use this code.  It displays the area of all Polylines separately.

The above lisp is very helpful to save a lot of time otherwise, we will have to do the above operation manually, which is time taking and sometimes results in errors.  

It is a lisp routine that helps too much, as a quantity surveyor needs to calculate the area and volume-based closed polylines.

The result gives a text-written area figure inside each polyline area.  When you type the command AREAON, nothing will seem to occur, on the screen, but in the background, the lisp has started functioning. 

First, it asks for the scale of the text, and then upon selection of polylines, it shows the area of every polyline inside it. Now you can leave the command by pressing the enter key, and all of the results will be displayed on the screen.  

One of my colleagues asked me for a lisp that calculates the area of multiple rectangles in the AutoCAD Drawing. He needed to show the area of many rectangles in the drawing. Here is a very useful lisp that we found to accomplish this task.  

AreaOn – Area of Polylines in AutoCAD

Below is the code of the lisp file.

;;; CADALYST 07/08  www.cadalyst.com/code 
;;; Tip 2292: AreaRon.lsp	Area of Closed Polylines	(c) 2008 Ronald Maneja

;;; PRODUCES TEXT CONTAINING AREA OF  SELECTED CLOSED POLYLINES
;;; AND PUTS THEM IN AREARON LAYER
;;; CREATED BY RON MANEJA 31JAN08
;;; USER INPUTS: SCALE, POLYLINE SELECTION
;;;



(defun C:AREARON (/
		  allx
		  ally
		  areaobj
		  counter
		  ctr
		  el
		  entity-name
		  entnamevla
		  mysset
		  pt
		  tst
		  vertex
		  x
		  y
		 )
  (vl-load-com)
  (COMMAND "_.UNDO" "BE")
  (set_var)
  (if (tblsearch "Layer" "AREARON")
    (command "._layer"
	     "_thaw"
	     "AREARON"
	     "_on"
	     "AREARON"
	     "_unlock"
	     "AREARON"
	     "_set"
	     "AREARON"
	     ""
    ) ;_ closes command
    (command "._layer"
	     "_make"
	     "AREARON"
	     "_color"
	     1
	     "AREARON"
	     ""
    ) ;_ closes command
  )
  (if (null sch)
    (setq sch 1.0)
  )
  (initget 6)
  (setq	temp (getreal (strcat "\nENTER SCALE <"
			      (rtos sch 2 2)
			      ">: "
		      )
	     )
  )
  (if temp
    (setq sch temp)
    (setq temp sch)
  )

  (if (null precision)
    (setq precision 1)
  )
  (initget 6)
  (setq	prec_temp (getint (strcat "\nHOW MANY DECIMAL PLACES?: <"
				  (rtos precision 2 2)
				  ">: "
			  )
		  )
  )
  (if prec_temp
    (setq precision prec_temp)
    (setq prec_temp precision)
  )
  (prompt "\nSELECT CLOSED POLYLINES:> ")
  (setq
    mysset  (ssget '((0 . "POLYLINE,LWPOLYLINE") (-4 . "&") (70 . 1)))
    counter 0
  )
  (if mysset
    (progn
      (while (< counter (sslength mysset))
	(setq allx	  0
	      ally	  0
	      ctr	  0
	      tst	  1
	      entity-name (ssname mysset counter)
	      EL	  (entget entity-name)
	      entnamevla  (vlax-ename->vla-object entity-name)
	      areaobj	  (vla-get-area entnamevla)
	)
	(while (assoc 10 el)
	  (setq	vertex (cdr (assoc 10 el))
		ctr    (+ ctr 1)
		x      (car vertex)
		y      (cadr vertex)
		allx   (+ allx x)
		ally   (+ ally y)
		EL     (cdr (member (assoc 10 el) el))
	  )
	)
	(setq x	 (/ allx ctr)
	      y	 (/ ally ctr)
	      pt (list x y)
	)
	(command "text" "j" "mc"
		 pt
		 (* sch 2.5)
		 "0"
		 (rtos areaobj 2 precision)
	)
	(setq counter (+ counter 1))
      )
    )
    (alert "\nNO CLOSED POLYLINES/LWPOLYLINES IN YOUR SELECTION"
    )
  )
  (reset_var)
  (princ)
(COMMAND "_.UNDO" "END")
)
(princ)


(defun set_var ()
  (setq oldlayer (getvar "clayer"))
  (setq oldsnap (getvar "osmode"))
  (setq temperr *error*)
  (setq *error* traperror)
  (setvar "osmode" 0)
  (princ)
)


(defun traperror (errmsg)
  (command nil nil nil)
  (if (not (member errmsg '("console break" "Function Cancelled"))
      )
    (princ (strcat "\nError: " errmsg))
  )
  (setvar "clayer" oldlayer)
  (setvar "osmode" oldsnap)
  (princ "\nError Resetting Enviroment ")
  (setq *error* temperr)
  (princ)
)



(defun reset_var ()
  (setq *error* temperr)
  (setvar "clayer" oldlayer)
  (setvar "osmode" oldsnap)
  (princ)
)

History 

The lisp code was written by Ron Maneja on 31 Jan 08. We appreciate their effort in writing this lisp and being helpful.  

There are some plugins also available for AutoCAD. Of course, you can buy the plugin as well. But if you are looking for something that is free this Lisp routine is just for you free of charge and ready to download.  

How to Calculate the Area in AutoCAD Download Free Lisp FileFree Online Training tutorial. This lisp uses a fantastic way to Calculate the Area in AutoCAD.

Scroll to Top