Jump to content

AutoLisp For Area Calculation


JCYK

Recommended Posts

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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
   )
 )


Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

  • 4 months later...
  • 1 year later...
  • 2 years later...
  • 1 year later...
  • 2 weeks later...

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...