Jump to content

auto area calculation table


harshad

Recommended Posts

hi 

i am looking for some large calculation stuff.

lisp To read area of selected polyline,  triangles ,rectangle, circle and other shapes with details of calculation.

lisp will give Area of an entity with single command. which will give detailed table of calculation for all the selected shape , But how does it calculate the area e.g. (base and height of the triangle and using ½ * base * height formula.) lisp  gives each shape  a unique number by selecting order , then marks the length of each side of the triangle on the drawing with the area displayed at the centre of the shape Then it prompts the user to specify a location for placing the area of each shape.

something like below 

any help thanks in advance

 

 

12.jpg.png

13.jpg.png

Link to comment
Share on other sites

The area is easy you use bpoly which has an AREA value. Try BPOLY then List L. It supports basically any closed shape.

 

Do you actually need the length and breadth ? 

 

Have a look at lee-mac.com has 3 area programs that may be usefull.

Link to comment
Share on other sites

to get you started , use (c:t1) or t1 in command line after loading for single polyline and (c:t2) or t2 for multiple polylines. But i don't believe I can add more value than bigal's suggestion and use one of master Lee's program's.

; rlx 10-mrt-2019 - https://www.cadtutor.net/forum/topic/66987-auto-area-calculation-table/
(defun c:t1 ( / doc spc text-height polly polly-points polly-center polly-area)
  (setq doc (vla-get-activedocument (vlax-get-acad-object)) spc (vla-get-block (vla-get-activelayout doc)))
  (setq text-height 5) ; adjust to fit your situation
  (if (and (setq polly (car (entsel))) (wcmatch (cdr (assoc 0 (entget polly))) "*POLYLINE"))
    (progn
      (setq polly-points (Get_Polly_Points polly) polly-center (Get_Polly_Center spc polly))
      (Put_Polly_Sizes (Get_Polly_Sizes polly-points) polly-center spc text-height)
      (Put_Polly_Area spc (Get_Polly_Area polly) (vlax-3d-point polly-center) text-height)
    )
  )
  (vla-Regen doc acActiveViewport)
)

;;; Gile
(defun Get_Polly_Points (pl / pa pt lst)(vl-load-com)
  (setq	pa (if (vlax-curve-IsClosed pl)(vlax-curve-getEndParam pl)(+ (vlax-curve-getEndParam pl) 1)))
  (while (setq pt (vlax-curve-getPointAtParam pl (setq pa (- pa 1))))(setq lst (cons pt lst))))

; s = space , e = polly (ent or obj)
(defun Get_Polly_Center ( s e / o r c )
  (or (= (type e) 'VLA-OBJECT) (setq o (vlax-ename->vla-object e)))
  (setq r (vlax-invoke s 'addRegion (list o)) c (vlax-get (car r) 'Centroid))
  (vla-delete (car r))(trans c 1 (vlax-get o 'Normal)))

; l is point list , return list with angle , midpoint & length for each vertice
(defun Get_Polly_Sizes (l)
  (mapcar '(lambda (a b) (list (angle a b) (mapcar '(lambda (x y) (/ (+ x y) 2)) a b)(distance a b)))
          l (append (cdr l) (list (car l)))))

; l = vertice list ((ang midp length)...) c = center of gravity , s = space , th = text height
(defun Put_Polly_Sizes (l c s th / x o p)
  (foreach x l
    (setq p (vlax-3d-point (polar (cadr x) (angle (cadr x) c) th)) o (vla-addtext s (rtos (last x) 2 2) p th))
    (mapcar
      '(lambda (p v)(vl-catch-all-apply 'vlax-put-property (list o p v)))
       (list 'alignment 'textalignmentpoint 'alignment 'rotation 'color)
       (list acAlignmentRight p acAlignmentMiddle (car x) acMagenta)
    )
  ) 
)

(defun Get_Polly_Area (e) (rtos (vla-get-area (vlax-ename->vla-object e)) 2 5))

; used for single polyline (c:t1) : s = string (area) , cpt = center point of gravity , th = text height
(defun Put_Polly_Area (spc s cpt th / to)
  (setq to (vla-addtext spc s cpt th))
  (mapcar
    '(lambda (p v)(vl-catch-all-apply 'vlax-put-property (list to p v)))
     (list 'alignment 'textalignmentpoint 'alignment 'rotation 'color) (list acAlignmentRight cpt acAlignmentMiddle 0 acRed)
  )
)

; used for multiple polylines (c:t2) : s = string (area) , cpt = centerpoint of gravity , th = text height , i = index
(defun Put_Polly_Area2 (spc s cpt th i / mto)
  (setq mto (vla-AddMText spc cpt (* 5 th) (strcat (itoa i) "\n" s)))
  (setq ip (vla-get-insertionpoint mto)) (vla-put-AttachmentPoint  mto 5) (vla-put-insertionpoint mto ip)
  (vl-catch-all-apply 'vlax-put-property (list mto 'color acRed))
)

; for multiple pollys
(defun c:t2 ( / doc spc i text-height ss to p)
  (setq doc (vla-get-activedocument (vlax-get-acad-object)) spc (vla-get-block (vla-get-activelayout doc))
        i 0 text-height 5)(setvar 'textsize text-height)
  (prompt "\nSelect polylines :")
  (if (and (setq ss (ssget ":L" '((0 . "LWPOLYLINE")))) (setq ss (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss)))))
    (foreach polly ss
      (setq polly-points (Get_Polly_Points polly) polly-center (Get_Polly_Center spc polly))
      (Put_Polly_Sizes (Get_Polly_Sizes polly-points) polly-center spc text-height)
      (Put_Polly_Area2 spc (Get_Polly_Area polly) (vlax-3d-point polly-center) text-height (setq i (1+ i)))
    )
  )
  (vla-Regen doc acActiveViewport)
  (princ) 
)
Edited by rlx
Link to comment
Share on other sites

thanks for replay 

in above code it give all 4 side length and area in centre it means lisp not detect shape of poly lines.

i want lisp to detect shape of poly lines and provide area (E.G. for rectangle area = length X width, for triangle area=1/2 X length X width ) like that

and put this into excel table or autocad table.(how we calculate in school means manual calculation )

it is to have multiple lisp for each shape .

thanks  

 

 

Edited by harshad
Link to comment
Share on other sites

Lee Mac has several routines on his site that can do this , I would only be re-creating one of his routines or in other words, be re-inventing the wheel... only thing he has to add is 'breadth' whatever that is , I only know bread & (bad) breath.

Link to comment
Share on other sites

😀 

i see his area label lisp i also want like that but his lisp showing area directly not showing how it get calculated 

i want that also.

thanks

Link to comment
Share on other sites

looking at your example , they are all triangles with a 90 degree angle and you want to see the length of all sides except the longest side but some of your triangles have 1 green string , some have 2 and some have none? So what is 'breadth' exactly?

Link to comment
Share on other sites

looks like you want the dimensions of the boundingbox for each polyline only with a twist in case of the most right one where the boundingbox should be aligned. Have to think how to do this last one, how to do this automatically that is... (should have paid more attention in math class I guess...)

 

ah , should have known : LM:minboundingbox

Edited by rlx
Link to comment
Share on other sites

looks more like auto / quick dimension job... have been four hours at my job and haven't done any work yet haha. Will have a look later and now try to get an Oscar for best actor playing a worker...

Link to comment
Share on other sites

rlx what was that time to go home 🙃

 

Harshad none of us worry to much about how we work out the area because we dont use any theory Autocad does it for us. Is this a school assignment ?

 

Re shapes we can look at a shape 3 points is a triangle, 4 is assumed to be a rectang 5 or more ? An  arc on side another. 

 

By the way your arc one side theroem is wrong. It uses the radius. The correct answer is to take area of a sector then subtract the triangle area.

 

If you google area theorem or land surveying you will find the correct formulas, I only spent 1 minute and found an answer for sector.

 

 

Edited by BIGAL
Link to comment
Share on other sites

I'm almost there with appie. Just a couple of loose ends like why isn't the first column of my table get filled in. And have to format some numbers , little stuf. But I had the same thought as Bigal , is this a school project because no one calculates the area better than AutoCAD , besides Bigal of course :P. Also , the big square is composed of 5 vertices in stead of 4 so I had to take the long road to prove it's a square and the silly thing on the left is made up from 2 vertices and 1 arc so same here : 3 coordinates is no guarantee its a triangle , at least not in OP's case. Anyways , despite this sabotage / these tests , I'll attach what I have so far but its not finished yet.

Harshad2.lsp

Link to comment
Share on other sites

it looking good See some comment in dwg 

 

he big square is composed of 5 vertices : that was rectangle only my drafting error.

Drawing3.dwg

Edited by harshad
Link to comment
Share on other sites

lisp look very good 

but i found one thing missing (non right angle triangle calculation )

please add that also refer below dwg. for calculation 

can we have option for block no. 1234 or abcd,  whatever we want 

thanks

Drawing3.dwg

Edited by harshad
Link to comment
Share on other sites

If you want a block just explode the table and make it a block. Routine places length of all vertices at this time. It's not hard to remove duplicates but to foolproof let the routine decide which one to remove I haven't cracked yet and not very important , not to me anyway 😛 because right now I have another appie in need of my help (else I have to do all the work myself and that's not what I had in mind when I got out of bed at 5 am this morning)

 

 

Harshad2.lsp

  • Like 1
Link to comment
Share on other sites

u done grate job

when lisp put all dim it look messy try to keep those 2 value only appear in table.

Quote

If you want a block just explode the table and make it a block

. :- i am not asking about that u not get my question 

i talking about numbering of polylines, now  we have 1234... like that if there we have an option for abcd.... it will help us 

in starting lisp should ask for numbering  or alphabet .

thanks.. for help

 

 

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