Jump to content
JCYK

AutoLisp For Area Calculation

Recommended Posts

JCYK

Hi All, I need some help here.

 

I'v been using a autolisp (obtained from a friend) to calculate floor area with AutoCAD 2007. However recently I've upgraded my AutoCAD to 2013 and I realised the lisp coudn't function completely.

 

I've attached the lisp file here, really hope someone can help to rectify so that it works for AutoCAD 2013. Fyi I knows nothing about writting lisp code... many thanks in advance! (not sure why this code looks so massive compared to others..)

 

To share with those who may be interested, this lisp allows you to select multiple polylines (eg. floor area), followed by select those polylines representing regions to be subtracted (eg. void area), it will help you tabulate all the polyline parcels (floor areas subtract floor void) with end result and with labels for each parcel.

 

Enjoy!

ATAB.lsp

Share this post


Link to post
Share on other sites
wishbonesr

Writes a file to the c:\ Modern Windoze OS's tend restrict writing at this level. There's a lot that could be updated with this program, and I don't know where to start.

 

I could be wrong, but it appears that Gildred (the author) intended the software to stop functioning in in the year 12084 month 93 day 11, and to contact him then for an update. :facepalm: I had a good laugh.

 

(ALERT"\Pls. Contact Gildred for update of this program.")

 

Almost all variables start with 'AT'.... Not to mention it looks decompiled as it resides on 5 lines is probably more suited for 500. Knowing this, I'd be shy to even download the code, not knowing it's copyright.

 

That being said, the write location is probably the problem, and you'd probably be able to search and edit the file yourself to point to a writable location.

 

Here are some alternatives that may help.

http://www.cadtutor.net/forum/showthread.php?22874-Calculate-Area-by-picking-internal-point/page3

 

http://www.lee-mac.com/areastofield.html

http://www.lee-mac.com/totallengthandarea.html

http://www.lee-mac.com/arealabel.html

http://www.lee-mac.com/areafieldtoattribute.html

Share this post


Link to post
Share on other sites
cadplayer

If you only calculate area of Polylines you can use my code.

It display area of all Polylines seperate after layer.

 

I´m very thankfully for all feedbacks to can do it better.

For example I´m missing a request if Polyline is closed or not

 

; question or ideas to my program
; contact me cadplayer@gmail.com!

(defun c:sa ( /
              i    ; increment
              en   ; entity
              lay  ; assoclist (entity . layer)
              layEn ; collect of lay
              layL ; used layer from picked areas
              ar   ; area from hatch
              arl  ; total area result
              )
 (setvar "CMDECHO" 0)
 (setq arl 0)
 (prompt (strcat "\nTool to calculate area from polylines" "\nSelect polylines! "))
 (if (/= (setq ss (ssget '((0 . "*POLYLINE")))) nil)
   (progn
     (setq i 0)
     (repeat (sslength ss)
       (setq en (cdr (assoc -1 (entget (ssname ss i)))))
       (setq lay (cons en (cdr (assoc 8 (entget en)))))
       (setq layEn (cons lay layEn))
       (cond
         ((/= en nil)
          (setq ar (_areaOfObject en))
          (setq arl (+ ar arl))
          )
         )
       (setq i (1+ i))
       )
     (princ (strcat "\n\n>>>> Total of all area: " (rtos arl 2 2)))
     (princ)
     (setq arl 0)
     )
   )
 (if (setq layL (_RemoveDuplicates (mapcar 'cdr layEn)))
   (repeat (length layL)
     (progn
       (foreach N layEn
         (if (= (cdr N) (car layL))
           (progn
             (setq ar (_areaOfObject (car N)))
             (setq arl (+ ar arl))
             (command "_layer" "_m" (cdr N) "")
             (command "_hatch" "ansi31" 0.1 0 "_s" (car N) "")
             )
           )
         )
       (princ (strcat "\n\nLayer: " (car layL) "\nTotal area: " (rtos arl 2 2)))
       (princ)
       )
     (setq layL (cdr layL))
     (setq arl 0)
     )
   )
 (princ)
 )

; calculate area of object
(defun _areaOfObject (en / curve area)
 (setq curve (vlax-ename->vla-object en))
 (if
   (vl-catch-all-error-p
     (setq
       area
        (vl-catch-all-apply 'vlax-curve-getArea (list curve))
       )
     )
   nil
   area
   )
 (progn
   (command "._area" "_O" en)
   (getvar "area")
   )
 )

; Erase duplicates in list
(defun _RemoveDuplicates ( lst / foo index )
   (defun foo (x)
       (cond
           ((vl-position x index))
           ((null (setq index (cons x index))))
       )
   )
   (vl-remove-if
      'foo
       lst
   )
 )


Share this post


Link to post
Share on other sites
JCYK

Hi Wishbonesr and cadplayer, thanks for your comments and help.

 

I've seen some of those links before, esp. from Lee Mac. They are awesome.

 

However I need the end result to be in this specific format as it is for submission purpose. If you try using the autolisp that i attached earlier, you can find out the type of format I am looking at. Some experts out there pls help~

 

Here's a more detail description of the autolisp function..

 

Situation: You have a number of big closed polylines (Floor Areas). Within each of these Green Areas there is a few small closed polylines (Void Areas).

 

Function of the autolisp:

- it will first ask you specify scale of drawing (eg. you key in 50, 100 or 200 etc, it'll adjust the text size accordingly).

- Select Floor Areas (you select the big closed polylines)

- Any Void Areas? (eg. Yes)

- Select Void Areas (you select the small closed polylines)

- Pick insertion point for tabulation (you pick a point on empty space)

** The end result tabulation is as per shown in the screen shot below. It will also gives a label (eg. A, B, C...) and the area figure inside each polyline area.

 

The above will help save a lot of time as without this lisp we'll have to do all the above manually... and repeatedly.

 

area tabulation.jpg

 

EXperts out there your big help is greatly appreciated. Thank you!

area tabulation.jpg

Share this post


Link to post
Share on other sites
wishbonesr

Spoke with my old man about this one. He told me that it was kinda common for some lispers (pre vlisp-compile days)to run a program on their routines to make it incredibly difficult to modify or debug. They then keep a copy of the original. He called it, "one form of job security".

With that being learned, I decided to look harder, and had to stop myself when I started to optimize.

 

I will say up front, that I make no claim to any portion of this code, and that all credit goes to Gildred.

 

Went so far as to mask all functions with a prefix, just in case of conflict; And nested as many as I could without seriously modifying. The problem, was in fact the write location for the temporary files it uses. It has been fixed, and should work on any system.

 

I was off on the number of lines this program should have been. Wound up being 940 without comments.

 

Tested ATAB only.

ATAB.LSP

Share this post


Link to post
Share on other sites
Raggi_Thor

Seems like there is a problem with apostrophes ( " ) in this file, it won't load.

Edited by Raggi_Thor

Share this post


Link to post
Share on other sites
JCYK

Wishbonesr....... you saved my life!!!!!! :D

 

It works fine in AutoCAD 2013! Thank you SO MUCH!!!!!!!!!!!!!!!!!! :thumbsup:

Share this post


Link to post
Share on other sites
CADSTORHAUG

How do I get this ATAB.lsp to dispaly S.F. and Acres? it displays sq.m.

Share this post


Link to post
Share on other sites
tortamneuk

thanks that's what i looking for!!!

Share this post


Link to post
Share on other sites
ThibG

Greetings,

 

The routine ATAB.lsp is awesome.

Just one question:

How can I set up a default text size for the measured area values?

Share this post


Link to post
Share on other sites
fadikm

Hi

Very good lisp i hope if can modify to be using as volume in th the same idea

Share this post


Link to post
Share on other sites
fadikm

Using the thickness of polylines

Share this post


Link to post
Share on other sites
devitg

Please show us your DWG and the task to do.

Share this post


Link to post
Share on other sites
fadikm

this routine help too much , as a quantiy surveyor need the same idea to calculate the volume based on closed polylines and its thickness and tabulate the results.

thanks

Share this post


Link to post
Share on other sites
BIGAL

It may be better to start a new post as your request is different and there are lots of Area lisps out there. You want something different. Include a dog and a detailed description of what is required.

 

It is very simple to read a pline area and multiply by thickness.

 

Also a quick glance the old code asked for scale it's better to use annotative text so plotted scale is taken care of 490 lines sounds massive.

 

Typed on iPad dog=drawing

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×