+ Reply to Thread
Results 1 to 7 of 7
  1. #1
    Forum Newbie
    Using
    AutoCAD 2008
    Join Date
    Oct 2008
    Posts
    6

    Default lisp to calculate total areas

    Registered forum members do not see this ad.

    please i need a lisp programming for autocad to caculate all the closed areas in a certain layer, also i need another program to calculate the total area of all the similar shapes ie: when u select assume a rectangle of dim(a,b) so it check all the similar rectangles and give the total summation area of the all of the same dimesnsions, anybody can help plz

  2. #2
    Luminous Being
    Using
    Civil 3D 2013
    Join Date
    Dec 2005
    Location
    GEELONG AUSTRALIA
    Posts
    5,437

    Default

    Search here first for "area lisp" lots of them out there.

  3. #3
    Forum Newbie
    Using
    AutoCAD 2008
    Join Date
    Oct 2008
    Posts
    6

    Default please help

    hello plz i need it to calculate every closed area including circules and elipses and all closed polylines if curved or straight, if any, thanks again

  4. #4
    Super Member ASMI's Avatar
    Using
    AutoCAD 2008
    Join Date
    Nov 2005
    Location
    Oceanus Procellarum, Moon
    Posts
    1,427

    Default

    Something like:

    Code:
    (defun c:sarea(/ aSum cSet cSet)
      (vl-load-com)
      (setq aSum 0)
      (if
        (setq cSet
    	   (ssget '((0 . "*POLYLINE,SPLINE,CIRCLE,ELLIPSE"))))
        (progn
          (foreach c(vl-remove-if 'listp
                      (mapcar 'cadr(ssnamex cSet)))
    	(if(vlax-curve-IsClosed c)
    	  (setq aSum(+ aSum(vlax-curve-GetArea c)))
    	  (ssdel c cSet)
    	  ); end if
    	); end foreach
          (princ(strcat "\nTotal area = " (rtos aSum)))
          (sssetfirst nil cSet)
          ); end progn
        ); end if
      (princ)
      ); end of c:sarea

  5. #5
    Forum Newbie
    Using
    AutoCAD 2008
    Join Date
    Oct 2008
    Posts
    6

    Default can somebody proffesional modify polyarea.lsp plz

    Thanks very much for the lisp "sarea" i used it but something missing because i drew with the polyline a closed shape including some arcs but couldnt calculate its area ie: like a closed barrel-vault or a closed dome but couldnt give me its area, it is saying zero knowing that it is closed.

    i want to give you this polyarea.lsp please so if anybody can help:
    It is calculating all the closed areas you imagine except the circles so can you please modify this lisp to take the circle in to consideration when giving the total areas summation:


    ;;POLYAREA.LSP - (c)
    ;;
    ;; Calculates the area of one or more closed polylines and
    ;; displays the result in an AutoCAD Alert Window.
    ;;
    (defun COLYAREA (/ a ss n du)
    (setq a 0
    du (getvar "dimunit")
    ss (ssget '((0 . "*POLYLINE"))))
    (if ss
    (progn
    (setq n (1- (sslength ss)))
    (while (>= n 0)
    (command "_.area" "_o" (ssname ss n))
    (setq a (+ a (getvar "area"))
    n (1- n)))
    (alert
    (strcat "The total area of the selected\nobject(s) is "
    (if (or (= du 3)(= du 4)(= du 6))
    ;
    ;The following 2 lines translate the area to square inches and feet
    ;for users using US engineering or architectural units:
    ;
    (strcat (rtos a 2 2) " square inches,\nor "
    (rtos (/ a 144.0) 2 3) " square feet.")
    ;
    ;In the following line, change the word "units" to whatever units
    ;you are using - meters, millimeters, feet, etc.
    ;
    (strcat (rtos a 2 3) " square units.")))))
    (alert "\nNo Polylines selected!"))
    (princ)
    )
    (alert
    (strcat "POLYAREA.LSP (c) "
    "\n\n Type POLYAREA to start"))
    (princ)


    please, i need all results in meter square only, so anybody can modify it, thank you all for help

  6. #6
    Super Member ASMI's Avatar
    Using
    AutoCAD 2008
    Join Date
    Nov 2005
    Location
    Oceanus Procellarum, Moon
    Posts
    1,427

    Default

    i used it but something missing because i drew with the polyline a closed shape including some arcs but couldnt calculate its area ie: like a closed barrel-vault or a closed dome but couldnt give me its area, it is saying zero knowing that it is closed.
    I think it visually closed but not closed by Close option (look properties window for this polyline). Now this check is removed an result in square meters (if drawing units is mm):

    Code:
    (defun c:sarea(/ aSum cSet)
      (vl-load-com)
      (setq aSum 0)
      (if(setq cSet(ssget '((0 . "*POLYLINE,SPLINE,CIRCLE,ELLIPSE"))))
          (foreach c(vl-remove-if 'listp(mapcar 'cadr(ssnamex cSet)))
    	  (setq aSum(+ aSum(vlax-curve-GetArea c)))
    	); end foreach
        ); end if
      (princ(strcat "\nTotal area = " (rtos(/ aSum 1000000)) " m2"))
      (princ)
      ); end of c:sarea
    Last edited by ASMI; 3rd Nov 2008 at 04:22 pm.

  7. #7
    Senior Member
    Computer Details
    VVA's Computer Details
    Operating System:
    Windows 7
    CPU:
    Intel Core i5-2400
    RAM:
    8 Gb
    Graphics:
    Nvidia Quadro 600
    Primary Storage:
    Seagate 500 GB + WD 750 GB
    Monitor:
    Philips 27"
    Using
    AutoCAD 2013
    Join Date
    Dec 2006
    Location
    Minsk, Belarus
    Posts
    427

    Default

    Registered forum members do not see this ad.

    This lisp calculate a total area of selected entities by layer
    Code:
    (defun c:SAL (/ m ss clist temp)
      ;;command SAL - Sum Area by Layer
      ;;posted Vladimir Azarko (VVA)
      ;;http://www.cadtutor.net/forum/showthread.php?t=28604
      (defun sort (lst predicate)
        (mapcar '(lambda (x) (nth x lst)) (vl-sort-i lst predicate))
      ) ;_ end of defun
      (defun combine (inlist is-greater is-equal / sorted current result)
        (setq sorted (sort inlist is-greater))
        (setq current (list (car sorted)))
        (foreach item (cdr sorted)
          (if (apply is-equal (list item (car current)))
            (setq current (cons item current))
            (progn
              (setq result (cons current result))
              (setq current (list item))
            ) ;_ end of progn
          ) ;_ end of if
        ) ;_ end of foreach
        (cons current result)
      ) ;_ end of defun
      (defun marea (lst / sum_len)
        (setq sum_len 0)
        (foreach item (mapcar 'car lst)
          (setq
            sum_len (+ sum_len
                       (if (vlax-property-available-p item 'Area)
                         (vla-get-area item)
                       ) ;_  if
                    ) ;_  +
          ) ;_ end of setq
        ) ;_ end of foreach
        (if (not (zerop sum_len))
          (princ
            (strcat "\n\t" (cdar lst) " = " (rtos (* sum_len m) 2 4))
          ) ;_ end of princ
        ) ;_ end of if
      ) ;_ end of defun
      (vl-load-com)
      (if (null *M*)
        (setq *M* 1)
      ) ;_ end of if
      (initget 6)
      (and
        (princ "\nEnter scale factor <")
        (princ *M*)
        (princ ">: ")
        (or (setq m (getreal)) (setq m *M*))
        (setq *M* m)
        (setq ss (ssget '((0 . "*POLYLINE,SPLINE,CIRCLE,ELLIPSE"))))
        (setq ss (mapcar
                   (function vlax-ename->vla-object)
                   (vl-remove-if
                     (function listp)
                     (mapcar
                       (function cadr)
                       (ssnamex ss)
                     ) ;_  mapcar
                   ) ;_ vl-remove-if
                 ) ;_ end of mapcar
        ) ;_ end of setq
        (mapcar '(lambda (x)
                   (setq temp (cons (cons x (vla-get-layer x)) temp))
                 ) ;_ end of lambda
                ss
        ) ;_ end of mapcar
        (setq clist (combine temp
                             '(lambda (a b)
                                (> (cdr a) (cdr b))
                              ) ;_ end of lambda
                             '(lambda (a b)
                                (eq (cdr a) (cdr b))
                              ) ;_ end of lambda
                    ) ;_ end of combine
        ) ;_ end of setq
        (princ
          "\n\n  Total area by layer :"
        ) ;_ end of princ
        (mapcar 'marea clist)
      ) ;_ end of and
      (princ)
    ) ;_  defun

Similar Threads

  1. Replies: 8
    Last Post: 15th Sep 2013, 06:18 am
  2. total hatch areas
    By happyunited in forum AutoCAD Drawing Management & Output
    Replies: 15
    Last Post: 5th Oct 2007, 04:41 pm
  3. How to calculate areas of multiple polylines?
    By xyz001 in forum AutoCAD Drawing Management & Output
    Replies: 4
    Last Post: 13th Feb 2007, 10:24 pm
  4. calculate areas using AutoCad LT
    By nickcardwell in forum AutoCAD Beginners' Area
    Replies: 2
    Last Post: 14th Nov 2006, 12:20 am
  5. calculate distance between two lines thru lisp
    By vivekgrs in forum AutoLISP, Visual LISP & DCL
    Replies: 1
    Last Post: 19th Jul 2006, 12:18 pm

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts