Announcements

The Autodesk Community Forums has a new look. Read more about what's changed on the Community Announcements board.

Is there a lisp file to calculate area & place text at ~center of polyline?

Anonymous

Is there a lisp file to calculate area & place text at ~center of polyline?

Anonymous
Not applicable

I'm looking for a lisp routine or command that will calculate area of a closed polyline and place text with the area value at the center of the polyline.  I need to do a lot of area calcs for a lot of small rooms?

Any thoughts are appreciated!

Thank you

Brian

0 Likes
Reply
Accepted solutions (2)
53,108 Views
49 Replies
Replies (49)

Anonymous
Not applicable

Haii Brother,

            Herewith i'm attached my lisp list for calculating areas.  also attached with command name.


@Anonymous wrote:

I'm looking for a lisp routine or command that will calculate area of a closed polyline and place text with the area value at the center of the polyline.  I need to do a lot of area calcs for a lot of small rooms?

Any thoughts are appreciated!

Thank you

Brian


 

JTBWorld
Advisor
Advisor
Accepted solution

I've added the command ATM to AreaText.lsp so you can select multiple objects and add the text at the boundary box center.


Jimmy Bergmark
JTB World - Software development and consulting for CAD and license usage reports
https://jtbworld.com

pendean
Community Legend
Community Legend

Kent1Cooper
Consultant
Consultant

>Here< is another.  And >this< one is for acres, and doesn't put the label in the middle but asks you where, but  it also makes a table of the areas, if that's something you might want to adapt to your usage.  [I haven't downloaded and tried either.]

Kent Cooper, AIA
0 Likes

Anonymous
Not applicable
Excellent - THANK YOU!!
0 Likes

Anonymous
Not applicable

The area calc to table is really great thanks!

0 Likes

Anonymous
Not applicable

This lisp routine was exactly what I was looking for.  Saving tons of time!  THANK YOU !!  How do I reduce the number of decimal places?  Thanks again!

0 Likes

JTBWorld
Advisor
Advisor
Accepted solution

Change below row:

(setq jtbfieldformula ">%).Area \\f \"%pr2%lu2%ct4%qf1 SQ. FT.\">%")

pr2 means two decimals, change to pr1 or pr0. 


Jimmy Bergmark
JTB World - Software development and consulting for CAD and license usage reports
https://jtbworld.com

0 Likes

Anonymous
Not applicable

Hi there. Great lisp routine. 

I was wondering if there is a way to not have the shaded box around the text? Makes it somewhat difficult to read. 

thanks for your help. 

0 Likes

JTBWorld
Advisor
Advisor

Set FIELDDISPLAY to 0.


Jimmy Bergmark
JTB World - Software development and consulting for CAD and license usage reports
https://jtbworld.com

0 Likes

Anonymous
Not applicable
Great! That works well.
Thank you very much for creating this and replying to my question!
Regards,

Matthias B.
0 Likes

khanabrar
Community Visitor
Community Visitor

sir, the lisp that calculating area of any closed polygon showing in sq in how to convert in sq ft pls


@Anonymous wrote:

Haii Brother,

            Herewith i'm attached my lisp list for calculating areas.  also attached with command name.


@Anonymous wrote:

I'm looking for a lisp routine or command that will calculate area of a closed polyline and place text with the area value at the center of the polyline.  I need to do a lot of area calcs for a lot of small rooms?

Any thoughts are appreciated!

Thank you

Brian


 


 

0 Likes

JTBWorld
Advisor
Advisor

@khanabrar What lisp file is it you are using?


Jimmy Bergmark
JTB World - Software development and consulting for CAD and license usage reports
https://jtbworld.com

0 Likes

nicole.rochette
Participant
Participant

Hi! I really need this routine but for Mac OS X Version 10.14 (x86_64).

Any chance someone has this or something similar?

What I basically need is:

1 - to have the area of each closed polygon to be placed at the center of the polygon as text

2 - ideally to create a table with these areas associated to the polygons.. this might be a bit difficult I guess

 

Any help appreciated!

0 Likes

dlanorh
Advisor
Advisor

Try this, it should work on a MAC as it only uses autolisp, and I think you can also use "getpropertyvalue"

 

It loops until you click on a blank area of screen. The area text at present is just the area converted to a string and is inserted on the current layer, in the current style at the current text height. Type PLA to run.

 

(defun *dxf* (code lst) (cdr (assoc code lst)))

(defun c:PLA (/ cmde ent e_typ cnt area vtx x_lst y_lst z_lst x_pt y_pt z_pt c_lst)

  (cond ( (/= 0 (getvar 'cmdecho)) (setq cmde (getvar 'cmdecho))  (setvar 'cmdecho 0)))

  (while (setq ss (ssget "_+.:E:S" '((0 . "POLYLINE,LWPOLYLINE") (-4 . "<OR") (70 . 1) (70 . 3)(-4 . "OR>"))))
    (setq ent (ssname ss 0)
          e_typ (*dxf* 0 (setq e_lst (entget ent)))
          cnt 0
          area (getpropertyvalue ent "area")
    );end_setq

    (cond ( (= e_typ "POLYLINE")
            (setq ent (entnext ent))
            (setq vtx (*dxf* 10 (entget ent)))
            (while (/= "SEQEND" (cdr (assoc 0 (entget ent))))
              (cond ( (/= "SEQEND" (cdr (assoc 0 (entget ent))))
                      (setq x_lst (cons (car vtx) x_lst)
                            y_lst (cons (cadr vtx) y_lst)
                            z_lst (cons (caddr vtx) z_lst)
                            cnt (1+ cnt)
                      );end_setq
                    )
              );end_cond
              (setq ent (entnext ent)
                    vtx (*dxf* 10 (entget ent))
              );end_setq
            );end_while
            (setq x_pt (/ (apply '+ x_lst) cnt)
                  y_pt (/ (apply '+ y_lst) cnt)
                  z_pt (/ (apply '+ z_lst) cnt)
            );end_setq
          )
          ( (= e_typ "LWPOLYLINE")
            (setq z_pt (*dxf* 38 e_lst)
                  v_lst (mapcar 'cdr (vl-remove-if-not '(lambda (x) (< 9 (car x) 11)) e_lst))
                  x_pt (/ (apply '+ (mapcar '(lambda (x) (car x)) v_lst)) (length v_lst))
                  y_pt (/ (apply '+ (mapcar '(lambda (x) (cadr x)) v_lst)) (length v_lst))
            );end_setq
          )
    );end_cond
    (setq c_lst (list x_pt y_pt z_pt))

    (entmakex (list (cons 0 "TEXT")
                    (cons 10  c_lst)
                    (cons 40 (getvar 'textsize))
                    (cons 1  (rtos area 2 3))
              );end_list
    );end_entmakex
  );end_while
  (if cmde (setvar 'cmdecho cmde))
);end_defun

I am not one of the robots you're looking for

0 Likes

dlanorh
Advisor
Advisor
If you need additions to the text string let me know

I am not one of the robots you're looking for

0 Likes

nicole.rochette
Participant
Participant

Thank you!! however I reached a first problem: when typing "PLA", the program does the "place" command...

0 Likes

dlanorh
Advisor
Advisor

I've updated the lisp as I noticed there was stil a vl- function within it (replaced) and I've change the command to PLAREA. It will now insert an MText object as opposed to a Text object as this was easier to centre within the polyline.

 

If PLAREA doesn't work for you replace the red item with whatever you want, remembering that the "c:" must preceed the new command name.

 

If you need the area string to have a prefix eg "Area : " with the units at the end please let me know.

 

 

(defun *dxf* (code lst) (cdr (assoc code lst)))

(defun c:plarea (/ cmde ent e_typ e_lst area vtx x_lst y_lst z_lst x_pt y_pt z_pt c_lst v_lst)

  (cond ( (/= 0 (getvar 'cmdecho)) (setq cmde (getvar 'cmdecho))  (setvar 'cmdecho 0)))

  (while (setq ss (ssget "_+.:E:S" '((0 . "POLYLINE,LWPOLYLINE") (-4 . "<OR") (70 . 1) (70 . 3) (70 . 5)(-4 . "OR>"))))
    (setq ent (ssname ss 0)
          e_typ (*dxf* 0 (setq e_lst (entget ent)))
          area (getpropertyvalue ent "area")
          v_lst nil
    );end_setq

    (cond ( (= e_typ "POLYLINE")
            (setq ent (entnext ent)
                  vtx (*dxf* 10 (entget ent))
            );end_setq
            (if (< (length vtx) 3) (setq vtx (reverse (cons 0.0 (reverse vtx)))))

            (while (/= "SEQEND" (cdr (assoc 0 (entget ent))))
              (setq v_lst (cons vtx v_lst)
                    ent (entnext ent)
                    vtx (*dxf* 10 (entget ent))
              );end_setq
              (if (< (length vtx) 3) (setq vtx (reverse (cons 0.0 (reverse vtx)))))
            );end_while

            (setq x_pt (/ (apply '+ (mapcar '(lambda (x) (car x)) v_lst)) (length v_lst))
                  y_pt (/ (apply '+ (mapcar '(lambda (x) (cadr x)) v_lst)) (length v_lst))
            );end_setq

            (if (= (setq sum (apply '+ (mapcar '(lambda (x) (caddr x)) v_lst))) 0.0) (setq z_pt 0.0) (setq z_pt (/ sum (length v_lst))))
          )
          ( (= e_typ "LWPOLYLINE")
            (setq z_pt (*dxf* 38 e_lst))
            (foreach pr e_lst
              (if (= (car pr) 10) (setq v_lst (cons (cdr pr) v_lst)))
            )
            (setq x_pt (/ (apply '+ (mapcar '(lambda (x) (car x)) v_lst)) (length v_lst))
                  y_pt (/ (apply '+ (mapcar '(lambda (x) (cadr x)) v_lst)) (length v_lst))
            );end_setq
          )
    );end_cond
    (setq c_lst (list x_pt y_pt z_pt))

    (entmakex (list (cons 0 "MTEXT")
                    (cons 100 "AcDbEntity")
                    (cons 100 "AcDbMText")
                    (cons 10  c_lst)
                    (cons 40 (getvar 'textsize))
                    (cons 71 5)
                    (cons 72 5)
                    (cons 1 (rtos area 2 3))
              );end_list
    );end_entmakex
  );end_while
  (if cmde (setvar 'cmdecho cmde))
);end_defun

I am not one of the robots you're looking for

nicole.rochette
Participant
Participant

There must be something I'm doing wrong.. I've used lisps before but never on MAC.

 

My workflow is:

- Copy the text you wrote on a brand new TextEdit file and save it (as .rtf)

- Rename the extension to .lsp

- APPLOAD it into Autocad

- It says loaded succesfully, but when closing the dialog window, the command bar reads "error syntax error"

- When typing "plarea" it does not recognise the command.

 

I tried changing the command name (in red) to other names but still the same problem...

0 Likes