Lisp for Area

Lisp for Area

shijomon_josephBCZCE
Participant Participant
324 Views
20 Replies
Message 1 of 21

Lisp for Area

shijomon_josephBCZCE
Participant
Participant

I am seeking a Lisp to assist with area calculations. The intended functionality is to allow selection of dimensions from a polyline, or a poly line itself after which the routine should automatically compute and add either the length or width. This tool is intended for use in wall elements represented in plan view, where the height is already known. The calculated area needs to be annotated on each wall throughout a large building project. 

Please hel me to find a solution for it.

0 Likes
Accepted solutions (2)
325 Views
20 Replies
Replies (20)
Message 2 of 21

Moshe-A
Mentor
Mentor

@shijomon_josephBCZCE  hi,

 

As you know, AutoCAD (in vanila version) does not knows what walls is 😀 it does knows AutoCAD objects like lines, arcs, plines. so to have an area calculation (post a sample dwg so we can understand how you are doing it manually) you need to draw close plines in each room. only then a lisp program can produce some area calculations.

 

Moshe

 

0 Likes
Message 3 of 21

shijomon_josephBCZCE
Participant
Participant

Hi Moshe,

Thanks for your response.

The issue I'm facing is that the wall is shown in its actual location, but I need to calculate the area of the wall based on its height, which is determined by the level. This makes it difficult to use traditional rectangular area calculations.

For example, if a wall is 10 meters in length and 7.5 meters in height, the width is not defined (L = 10, W = ?, H = 7.5), and this information is not available directly from the plan view. Therefore, I’m unable to pick the area using standard methods. 

I’m looking for a Lisp program that can help me calculate the wall area by selecting a polyline and entering the height during selection. The program should then annotate the calculated area directly at the wall’s location along with the dimensions.

Let me know if you have any suggestions or if such a tool is available.

0 Likes
Message 4 of 21

Moshe-A
Mentor
Mentor

post a sample dwg so we can understand how you are doing it manually

if you want to input the length, width, height for each pline then an old manual calculator will do the same job as lisp

 

 

0 Likes
Message 5 of 21

shijomon_josephBCZCE
Participant
Participant

Hi

please find the picture of the wall and the length in 2D plan marked with dimensions. And the height of the wall is 7.7m. So, i need to manually calculate the area to annotate each one of them.

Example = 9.78 m length of a wall with the height of 7.7m = 75.306m² 

0 Likes
Message 6 of 21

Moshe-A
Mentor
Mentor

So you want a lisp the let you select a dimension (or a wall face) ask you the height than write down the area

the height of all walls is not the same?

 

why can't you post a sample dwg?

 

 

0 Likes
Message 7 of 21

autoid374ceb4990
Collaborator
Collaborator

Your second picture is quite different from the first.   Please post the DWG files.

0 Likes
Message 8 of 21

Moshe-A
Mentor
Mentor

@shijomon_josephBCZCE  hi,

 

Here is my suggestion to think of 😀

create a layer (say call it "geo_layer") draw\trace using pline wall faces. set each pline with elevation (as wall height) use properties palette

warp the following program in calarea.lsp file than load it in your drawing.

run the lisp: CALAREA and select all plines (only on geo_layer) 'boom' you will get all areas.

 

you can control a few properties in code (starting from line# 32)

 

; define some constants
(setq GEOLAYER "geo_area") ;  the layer the plines will be found , set it any color you like
(SETQ TARLAYER "text_area") ; the layer text (cal area) will be laid , set it any color you like
(SETQ TEXTSIZE 0.3) ; text height in meters
(setq TEXTOFSET 3)  ; text offset factor

 

the program use the current text style, so make sure you set the right one.

 

enjoy

Moshe

 

;;; calarea.lsp
;;; by Moshe-A
;;; SEP 2025

(vl-load-com) ; load activex support

(defun c:calarea (/ cal_text_pos readable_text ; local functions
		    GEOLAYER TARLAYER TEXTSIZE TEXTOFSET
		    adoc layers modelSpace ss ename AcDbPLine plen hgt mpx mp0 mp1 p0 p1 p2 AcDbText)

 (defun cal_text_pos (t0 t1 t2)
  (polar t2 (+ (angle t0 t1) (* pi 0.5)) (* 0.3 3))
 ); cal_text_pos

 (defun readable_text (t0 t1 / a0)
  (setq a0 (angle t0 t1))

  (if (and (> a0 (* pi 0.5)) (< a0 (* pi 1.5)))
   (+ a0 pi)
   a0
  ); if
 ); readable_text


 ; here start c:calarea 
 (setq adoc (vla-get-activedocument (vlax-get-acad-object)))
 (vla-startUndomark adoc)
  
 (setq layers (vla-get-layers adoc))
 (setq modelSpace (vla-get-modelspace adoc))

 ; define some constants
 (setq GEOLAYER "geo_area") 	; const
 (SETQ TARLAYER "text_area")	; const
 (SETQ TEXTSIZE 0.3)		; const
 (setq TEXTOFSET 3)		; const
  
 (if (not (vl-catch-all-error-p (vl-catch-all-apply 'vla-item (list layers TARLAYER))))
  nil
  (vla-add layers TARLAYER)
 )

 (if (setq ss (ssget (list '(0 . "lwpolyline") (cons '8 GEOLAYER))))
  (foreach ename (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss)))
   (setq AcDbPLine (vlax-ename->vla-object ename))
   (setq plen (vla-get-length AcDbPLine))	; pline length
   (setq hgt (vla-get-elevation AcDbPLine))	; elevation

   (setq mpx (* (vlax-curve-getEndParam ename) 0.5)) ; middle param
   (setq mp0 (fix mpx))
   (setq mp1 (1+ (fix mpx)))

   (setq p0 (vlax-curve-getPointAtparam ename mp0))
   (setq p1 (vlax-curve-getPointAtParam ename mp1))
   (setq p2 (vlax-curve-getPointAtParam ename mpx))

   (setq AcDbText (vla-addText modelSpace (strcat (rtos (* plen hgt)) "m" (chr 178)) (vlax-3d-point p2) 0.3))
   (vla-put-rotation AcDbText (readable_text p0 p1))
   (vla-put-alignment AcDbText acAlignmentMiddle)
   (vla-put-textAlignmentPoint AcDbText (vlax-3d-point (cal_text_pos p0 p1 p2)))
   (vla-put-layer AcDbText TARLAYER) 
    
   (vlax-release-object AcDbText)
   (vlax-release-object AcDbPLine)
  ); foreach
 ); if

 (vlax-release-object modelSpace)
 (vlax-release-object layers)

 (vla-endUndoMark adoc)
 (vlax-release-object adoc)
  
 (princ)
); c:calarea

 

 

0 Likes
Message 9 of 21

Sea-Haven
Mentor
Mentor

My $0.05 you can set a wall "THICKNESS" this is the wall height so picking a line and just multiply by the thickness, you could select lots of lines and set Thickness. Use Properties. In this image the wall height has been set but is viewed in a 3d view. Just type thickness set a value then draw a line, then vpoint -1,-1,1 you will see the thickness. You wont see Thickness in PLAN view.

 

SeaHaven_0-1756863879522.png

 

0 Likes
Message 10 of 21

Moshe-A
Mentor
Mentor

@shijomon_josephBCZCE ,

 

Opps i thought about thickness but used elevation - sorry my bad 😂 that's what happen when you do it late at night.

so @Sea-Haven you go it right.

 

Attach is the corrected version.

 

Moshe

0 Likes
Message 11 of 21

shijomon_josephBCZCE
Participant
Participant

Hi Moshe

Thankyou very much for your support.  

Unfortunately, the lisp notworking as you explained. see the image attached here for more clarity. 

Once the command is activated then it prompts to select objects...  But when i select the poly line it says "0" found

0 Likes
Message 12 of 21

shijomon_josephBCZCE
Participant
Participant

Hi ,

Thankyou for your reply. unfortunately, this method is not suitable for me. i need all pure in 2D drawing

0 Likes
Message 13 of 21

shijomon_josephBCZCE
Participant
Participant

Hi,

Please find here a sample drawing attached.

I need the area annotated in each dimension with uniform wall height 7.7m

0 Likes
Message 14 of 21

shijomon_josephBCZCE
Participant
Participant

Dwg file attached

0 Likes
Message 15 of 21

Moshe-A
Mentor
Mentor
Accepted solution

@shijomon_josephBCZCE ,

 

change "geo_layer" to "geo_area"

 

; next line comes from calarea.lsp

(setq GEOLAYER "geo_area") ;  the layer the plines will be found , set it any color you like

 

prepare your drawing by tracing your wall for calarea on "geo_area" layer than select all these plines and set them 7.7m thickness

 

now it will work 😀

 

0 Likes
Message 16 of 21

shijomon_josephBCZCE
Participant
Participant

Dear Moshe

I am very thankful to you.  Its worked well as i expected and saved my life to easy... 

Thank you very much...

0 Likes
Message 17 of 21

Moshe-A
Mentor
Mentor
Accepted solution

@shijomon_josephBCZCE 

 

Ahhh 😆 that was quick, glade i could help

 

study the properties you can set and use them.

 

with :

(setq TEXTOFSET 3)		; const

 

You can control the offset of the text from face of the wall.

if you make changes to your walls do not forget to stretch the "text_area" plines also and run the command again.

 

cheers

Moshe

0 Likes
Message 18 of 21

shijomon_josephBCZCE
Participant
Participant

Sure... 🙏

0 Likes
Message 19 of 21

komondormrex
Mentor
Mentor

somewhat same with fields

(defun c:add_area (/ dim_sset)
  (foreach dim (mapcar 'vlax-ename->vla-object (vl-remove-if 'listp (mapcar 'cadr (ssnamex (setq dim_sset (ssget '((0 . "dimension"))))))))
    (vla-put-textoverride dim (strcat "<>\\P%<\\AcObjProp.16.2 Object(%<\\_ObjId "
                      (itoa (vla-get-objectid dim))
                      ">%).Measurement \\f \"%lu2%ct8[7.7]\">% m\\U+00B2"
                  )
    )
  )
  (command "_updatefield" dim_sset "")
  (princ)
)
0 Likes
Message 20 of 21

Sea-Haven
Mentor
Mentor

"I need all pure in 2D drawing" thickness is like a quasi 3d aspect, you will not see it in any 2d dwg the only time you will see it is if you view in 3d. So still suggest use thickness, you can set various parts of your dwg with different "thickness" so will work out area matching that wall height. I would suggest you just give it a try.

 

This is your dwg with 2 different wall heights. You can only see it in a 3d view. For all intents and purposes its 2D.

 

0 Likes