Lisp to calculate area of all closed polylines selected

Lisp to calculate area of all closed polylines selected

MikeKovacik4928
Advisor Advisor
7,944 Views
7 Replies
Message 1 of 8

Lisp to calculate area of all closed polylines selected

MikeKovacik4928
Advisor
Advisor

Hi there Autocadders world wide as well as Autodesk employees

 

Can someone give me a lisp that calculates the area of all closed polylines selected, (in one operation)

The area add command is okay, except if you have over a hundred closed polylines

whose areas you want to add up, then selecting over a hundred entities separately becomes tedious

 

Mike Kovacik

Autocad/Inventor 2d/3d draughtsman/designer

Joburg

South Africa

 

0 Likes
Accepted solutions (1)
7,945 Views
7 Replies
Replies (7)
Message 2 of 8

JTBWorld
Advisor
Advisor
Accepted solution

Maybe this can help. AreaM.lsp Calculates the total area of selected objects


Jimmy Bergmark
JTB World - Software development and consulting for CAD and license usage reports
https://jtbworld.com

Message 3 of 8

MikeKovacik4928
Advisor
Advisor

Perfect Jimmy !!!

Thanks

 

Mike

0 Likes
Message 4 of 8

Anonymous
Not applicable

Jimmy,

 

I installed the lisp that calculates the total area of multiple objects at once, but it doesn't appear to be working. After I run the AreaM command and select the objects, the dynamic input/command line goes blank and I don't get a measurement. 

 

Thoughts?

0 Likes
Message 5 of 8

JTBWorld
Advisor
Advisor

What does the command line history show, what type of objects and what version of AutoCAD? 


Jimmy Bergmark
JTB World - Software development and consulting for CAD and license usage reports
https://jtbworld.com

0 Likes
Message 6 of 8

jleeNJTPV
Community Visitor
Community Visitor

Is there a way for the command to work by selecting all the polylines first, then running AREAM? Currently it only works if you run the command before selecting the polylines.

0 Likes
Message 7 of 8

BlackBox_
Advisor
Advisor

@jleeNJTPV wrote:

Is there a way for the command to work by selecting all the polylines first, then running AREAM? Currently it only works if you run the command before selecting the polylines.


This should help; it accepts implied selection, and *IF* you have loaded DosLIB, it will copy the result to clipboard: 

 

(vl-load-com)

(defun c:AreaM (/ *error* acDoc ss area prec)

  (defun *error* (msg)
    (if ss (vla-delete ss))
    (cond ((not msg))                                                   ; Normal exit
          ((member msg '("Function cancelled" "quit / exit abort")))    ; <esc> or (quit)
          ((princ (strcat "\n** Error: " msg " ** ")))                  ; Fatal error, display it
    )
    (princ)
  )
  
  (if (ssget "_:L"
             '((-4 . "<OR")
               (0 . "POLYLINE")
               (0 . "LWPOLYLINE")
               (0 . "CIRCLE")
               (0 . "ELLIPSE")
               (0 . "SPLINE")
               (0 . "REGION")
               (-4 . "OR>")
              )
      )
    (progn
      (vlax-for	x (setq	ss
			 (vla-get-activeselectionset
			   (setq acDoc (vla-get-activedocument
					 (vlax-get-acad-object)
				       )
			   )
			 )
		  )
	(setq area (cons (vla-get-area x) area))
      )
      (prompt (strcat "\nTotal area: "
                      (rtos (setq area (apply '+ area)))
;;; example for reporting the area in multiple units:
;;;		      (rtos (setq area (apply '+ area)) 2 (setq prec (getvar 'luprec)))
;;;		      " SF | "
;;;		      (rtos (/ area 9.0) 2 prec)
;;;		      " SY | "
;;;		      (rtos (/ area 43560.0) 2 prec)
;;;		      " AC "
	      )
      )
      ;; if doslib is available, copy result to clipboard
      (if dos_clipboard (dos_clipboard (rtos area)))
    )
  )
  (*error* nil)
)

 

HTH 


"How we think determines what we do, and what we do determines what we get."

Sincpac C3D ~ Autodesk Exchange Apps

Message 8 of 8

Sea-Haven
Mentor
Mentor

Just a comment it makes sense to me to say sort the plines based on say layer names, then can make say a table of the resulting total area by layer. Yes have send a table to Excel or just write answer to Excel.

0 Likes