Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

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

49 REPLIES 49
SOLVED
Reply
Message 1 of 50
Anonymous
49039 Views, 49 Replies

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

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

49 REPLIES 49
Message 21 of 50
dlanorh
in reply to: nicole.rochette


@nicole.rochette wrote:

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


Don't save as .rtf, this may be causing the problem, always save as .txt. I have attached the lisp to save you having to cut and paste.if you get any error whilst loading or closing the dialog the it won't run.

 

The rest seems OK. There may be another problem in that I single quote system variables. It is possible that this could be causing an error, but I don't know anything about running AutoCAD on MAC's so I'm not going to be any good there. Perhaps a question in the AutoCAD MAC Forum HERE

 

 

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

Message 22 of 50
nicole.rochette
in reply to: dlanorh

Thanks!! This worked!!!!!

 

Would it be too much to ask how I can make it:

1. have a prefix that numbers each polygon as I select it (eg "Lote 1", "Lote 2", etc).

2. have a sufix eg "m2" after the units

3. have only 2 decimals (eg "40.17 m2")

 

So that the result would be:

Lote 1

40.17 m2

 

Lote 2

34.12 m2

 

etc.

 

 

If this is not possible I understand. Your lisp works perfectly anyhow!

 

Message 23 of 50
dlanorh
in reply to: nicole.rochette

I should have time to sort this out this evening. It isn't too difficult. I'll prompt for a start number with a default of 1, which will give you the option of continuing from previous.

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

Message 24 of 50
dlanorh
in reply to: nicole.rochette

Attached is the latest lisp.

 

Please Note :

 

1. I have added an error routine.

 

2. The lisp initially asks for the start Lot Number. Pressing return or right mouse click will accept the default <1>  otherwise enter the integer of your choice. It will not accept 0 (zero) or a negative number.

 

3. As previously, the lisp will only process CLOSED polylines of types LWPolyline (with any elevation) and Polyline

(LWPolylines with fit or spline fit curves or Old 2dPolylines).

 

4. As requested the MText is now formatted (Middle Centre) and on two lines, the Top line has the Lot No and the Bottom line the area with m2.

 

Any changes let me know.

 

 

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

Message 25 of 50
nicole.rochette
in reply to: dlanorh

THANKS!!

It works just perfect. you have helped me so much!! 😊

The fact that one can start the count at any desired number is amazing btw... 

 

I'm really new to this ... I hope to learn more in the future. For example, if I need to change the prefix do I just modify the routine and replace "Lote" with something else? And same with the "m2" at the end?

Message 26 of 50
dlanorh
in reply to: nicole.rochette

    (setq ent (ssname ss 0)
          e_lst (entget ent)
          area (getpropertyvalue ent "area")
          txt (strcat "Lote " (itoa cnt) "\\P" (rtos area 2 2) "m\U+00B2")
          v_lst nil
    );end_setq

The red line is the line you need to change

 

"Lote " is the prefix

(itoa cnt) converts the integer cnt (count) to a string

"\\P" is the MText hard return string

(rtos area 2 2) This converts the area into a decimal string (first 2) with two decimal places (second 2)

"m\U+00B2" This is metres (m) and the superscript 2

 

Don't worry about the decimal part, it works equally as well in architectural units since the area returned will be in the units set in the drawing.

 

e.g If feet are the base units it just forces it to decimal feet etc, you'll just need to alter the m to ft; or if the base units are mm (millimetres) you should change it to mm

 

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

Message 27 of 50
nicole.rochette
in reply to: dlanorh

Hi, I've been using this routine and it's very helpful!

Now I need to just number the lots (I don't need the area for each one), so I've been trying to edit the routine eliminating the area part of it, but I know nothing about programming and I don't seem to get it to work.

 

Can you help me?

I just need it to number the lots as I select them 

 

Lote 1

Lote 2

Lote 3

 etc

 

Thanks again!

Message 28 of 50
dlanorh
in reply to: nicole.rochette

(setq ent (ssname ss 0)
          e_lst (entget ent)
          area (getpropertyvalue ent "area")
          txt (strcat "Lote " (itoa cnt) "\\P" (rtos area 2 2) "m\U+00B2")
          v_lst nil
    );end_setq

Copy the lisp (so you retain the original) and remove the red bits

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

Message 29 of 50
nicole.rochette
in reply to: dlanorh

Perfect thanks! And is there a way to modify the resulting text size? I see a part that says "textsixe" at the end but don't know what number controls it

Message 30 of 50
dlanorh
in reply to: nicole.rochette

I have updated the lisp (attached).

You are now asked if you want to add the area (Yes or No) default Yes. This works using the dynamic prompt so a return or right mouse click (if your mouse is set up that way) should return the default.

 

You are then asked for the start number for the Lots (default 1)

 

You are then asked for the text size (default is the current set textsize)

 

Everything will then work as before.

 

Any problems give me a shout.

 

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

Message 31 of 50
nicole.rochette
in reply to: dlanorh

Just perfect thank you! 😊

Message 32 of 50
Anonymous
in reply to: dlanorh

Hi, I have read your posts on how to modify the script, but I'm having trouble with the return values.

My file is in millimetre units, but I would like to return the area values back as square meters.

 

 

 

(initget 6)
(setq cnt (cond ((getint "\nEnter Area Start No : <1> ")) (1)))

(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 (rh:dxf 0 (setq e_lst (entget ent)))
area (getpropertyvalue ent "area")
txt (strcat "Area " (itoa cnt) "\\P" (rtos area 2 2) "mm\U+00B2")
v_lst nil
);end_setq

 

I know its the area in red, however, because the file is measured in mm I need to return meters so the decimal has to move 6 places, but only show two decimal places: (rtos area 8 2). I can't seem to make this work when I override the value. 

 

Thank you for the script!

 

Message 33 of 50
Kent1Cooper
in reply to: Anonymous


@Anonymous wrote:

....

txt (strcat "Area " (itoa cnt) "\\P" (rtos area 2 2) "mm\U+00B2")....

 

I know its the area in red, however, because the file is measured in mm I need to return meters so the decimal has to move 6 places, but only show two decimal places: (rtos area 8 2). I can't seem to make this work when I override the value. 

....


 

>Read about (rtos)< in the AutoLisp Reference.  The number you are changing from 2 to 8 is not a divider or some kind, but the mode, and the choices do not go as far as 8.  You still want it to be decimal mode, which is the first 2.

 

You need to divide the area value for the correct ratio -- try:

 

(rtos (/ area 1e6) 2 2)

 

and of course change the "mm" to just "m".

Kent Cooper, AIA
Message 34 of 50
dduroux1
in reply to: Kent1Cooper

Is there a reason why this won't work on a large polyline? I select a closed polyline, and nothing happens, the lisp just stops. The area is 226404.8009 sf.

Message 35 of 50
Anonymous
in reply to: dduroux1

Sorry, but can't help as I don't know much about lisp routines.
Good luck.

Matthias
Message 36 of 50
dduroux1
in reply to: dlanorh

Is there a reason why this won't work on a large polyline? I select a closed polyline, and nothing happens, the lisp just stops. The area is 226404.8009 sf.

 
Message 37 of 50
Kent1Cooper
in reply to: dduroux1


@dduroux1 wrote:

Is there a reason why this won't work on a large polyline? ....


Which "this" are you using?  There are a lot of code offerings on this thread....

Kent Cooper, AIA
Message 38 of 50
dduroux1
in reply to: Kent1Cooper

The PLAREA lisp that @nicole.rochette had requested made by dlanorh

Message 39 of 50
Kent1Cooper
in reply to: dduroux1

I expect it's this line:

(while (setq ss (ssget "_+.:E:S" '((0 . "POLYLINE,LWPOLYLINE") (-4 . "<OR") (70 . 1) (70 . 3) (70 . 5) (-4 . "OR>"))))

 

The 70-code entry in LWPolyline entity data has only two possible included bits:

Kent1Cooper_0-1606045608605.png

[@dlanorh , it can never be 3 or 5 -- it can be only 0, 1, 128 or 129.]  I think you're picking a closed Polyline with linetype generation enabled, and that entry is (70 . 129), so it won't select it.

 

Try disabling linetype generation for that Polyline, and see whether it works.  But since linetype generation will probably be important to you at least sometimes, better to change that line to this:

(while (setq ss (ssget "_+.:E:S" '((0 . "POLYLINE,LWPOLYLINE") (-4 . "<OR") (70 . 1) (70 . 129) (-4 . "OR>"))))

 

Or see >this< for a slightly more concise way to find all closed ones, whether or not linetype generation is enabled, and that will continue to work if other bit value possibilities are added into the 70 slot.

Kent Cooper, AIA
Message 40 of 50
dlanorh
in reply to: Kent1Cooper

The lisp is set up to select polylines (curved or spline fitted lwpolylines) and lwpolylines so (70 . 3) and (70 . 5) are valid

 

Pehaps replacing it with

 

 (setq ss (ssget "_+.:E:S" '((0 . "POLYLINE,LWPOLYLINE") (-4 . "&=") (70 . 1))))

 

to account for plinegen lwpolylines. (Not tested)

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

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Forma Design Contest


AutoCAD Beta