PDA

View Full Version : Area of Hatched Objects


mr_pessimist_684
2009-03-29, 10:09 AM
is there a lisp that will report the area of every hatched object and can also add the area of the total hatched area selected? this can be done by the area command but i want in in square meter if possible..please help

'gile'
2009-03-29, 11:04 AM
Hi,

(defun c:HatchArea (/ cnt tot ss)
(vl-load-com)
(setq cnt 0
tot 0
)
(print "\nSelect hatches (or type Enter for all): ")
(if (or (ssget '((0 . "HATCH"))) (ssget "_X" '((0 . "HATCH"))))
(progn
(vlax-for h (setq
ss (vla-get-ActiveselectionSet
(vla-get-ActiveDocument (vlax-get-acad-object))
)
)
(setq cnt (1+ cnt)
tot (+ tot (vla-get-Area h))
)
)
(vla-delete ss)
)
)
(princ (strcat "\nTotal area: "
(rtos tot)
" ("
(itoa cnt)
" objects)"
)
)
(princ)
)

mr_pessimist_684
2009-03-30, 06:53 AM
Hi,

(defun c:HatchArea (/ cnt tot ss)
(vl-load-com)
(setq cnt 0
tot 0
)
(print "\nSelect hatches (or type Enter for all): ")
(if (or (ssget '((0 . "HATCH"))) (ssget "_X" '((0 . "HATCH"))))
(progn
(vlax-for h (setq
ss (vla-get-ActiveselectionSet
(vla-get-ActiveDocument (vlax-get-acad-object))
)
)
(setq cnt (1+ cnt)
tot (+ tot (vla-get-Area h))
)
)
(vla-delete ss)
)
)
(princ (strcat "\nTotal area: "
(rtos tot)
" ("
(itoa cnt)
" objects)"
)
)
(princ)
)

This is working fine! Thanks for the quick reply, but can i have the area in square meter please? so i do not have to count the decimal point backward

l3ch
2009-03-30, 09:31 AM
The problem is, the objets have an area in units. No specific units, only units. So you must decide which units are they and be consistent. If you draw in meters, object's area is in meters; if you draw in milimeters, area is in milimeters.

Then, what is your case? If you draw in meters and you want area without decimals, then change: (rtos tot 2 0). If you draw in milimeters, then (rtos (/ tot 1e6) 2 0). As a rule, (rtos (/ tot factor) 2 0), where factor is the area of one square meter in your units. But remember, not your current units but the units you drawn that objet.

If you never change your units, then the problem is easy to solve. But, if you do as many people here, changing from meters to mm and back... at least make sure INSUNITS is always consistent.

mr_pessimist_684
2009-04-01, 05:44 AM
The problem is, the objets have an area in units. No specific units, only units. So you must decide which units are they and be consistent. If you draw in meters, object's area is in meters; if you draw in milimeters, area is in milimeters.

Then, what is your case? If you draw in meters and you want area without decimals, then change: (rtos tot 2 0). If you draw in milimeters, then (rtos (/ tot 1e6) 2 0). As a rule, (rtos (/ tot factor) 2 0), where factor is the area of one square meter in your units. But remember, not your current units but the units you drawn that objet.

If you never change your units, then the problem is easy to solve. But, if you do as many people here, changing from meters to mm and back... at least make sure INSUNITS is always consistent.

That's my problem man, commonly we draw in millimeters but we present the area in square meters

irneb
2009-04-01, 07:16 AM
You could use the cvunit function to make these conversions easier to understand. E.g. (cvunit tot "sq millimeters" "sq meters").

Edit: attached is a sample which I wrote a while back. It allows for getting areas from any entity which has areas (e.g. CIRCLE, ELLIPSE, HATCH, LWPOLYLINE, POLYLINE, REGION, SPLINE) and then allows adding & subtracting to a total. It then places the "result" as a FIELD inside a TEXT, MTEXT, ATTRIB or MLeader.

Just load & type DIMAREA, hit Enter if you want to change the settings (see below for settings) or pick the text you want to have the result shown in. Then select all the entities you want to add together, then all those you want subtracted from the total.

Options are as follows:

How to add to text: Override, Prefix or Suffix
Add any prefix to the result
Add any suffix to the result
Conversion of units, e.g. mm=m ... no need for sq as this is added because it's an area calculation
Precision, i.e. how many digits after the point to be shown

mr_pessimist_684
2009-04-04, 02:23 PM
You could use the cvunit function to make these conversions easier to understand. E.g. (cvunit tot "sq millimeters" "sq meters").

Edit: attached is a sample which I wrote a while back. It allows for getting areas from any entity which has areas (e.g. CIRCLE, ELLIPSE, HATCH, LWPOLYLINE, POLYLINE, REGION, SPLINE) and then allows adding & subtracting to a total. It then places the "result" as a FIELD inside a TEXT, MTEXT, ATTRIB or MLeader.

Just load & type DIMAREA, hit Enter if you want to change the settings (see below for settings) or pick the text you want to have the result shown in. Then select all the entities you want to add together, then all those you want subtracted from the total.

Options are as follows:

How to add to text: Override, Prefix or Suffix
Add any prefix to the result
Add any suffix to the result
Conversion of units, e.g. mm=m ... no need for sq as this is added because it's an area calculation
Precision, i.e. how many digits after the point to be shown


Thanks! i'll try this one out

mr_pessimist_684
2009-04-07, 08:21 AM
Thanks! i'll try this one out

Why is it asking me to select a text? is it possible to modify the AREA > Add > object command wherein i can see in MM the area of the current selection in MM and the total area in MM also...and is it possible to select the area of a Regioned Object using area command also...thanks

irneb
2009-04-07, 08:41 AM
It's possible yes, I just did it the other way round: asking where to place the answer before selecting the entities. I could have change to a select first, but then it's not so easy to go to the Options idea. For a running area total, I'll probably have to use Pick Entity instead of Select multiple entities ... but maybe not :? ... will look into it and revert back.

When you say "Regioned Object", what exactly do you mean? If it's a REGION then yes, you can obtain the area of this using either my routine or the standard AREA command. If you want to select the entity(ies) which were used to create the REGION ... then no there's no way to do this :cry:. If you mean to select the entities used to create an Associative hatch, then it's possible to write some lisp for that, but much simpler just to select the hatch. If you mean you wish to pick a point like you would by creating a hatch or region ... then a rewrite of my code might do it, but the standard AREA command cant.

mr_pessimist_684
2009-04-09, 06:17 AM
It's possible yes, I just did it the other way round: asking where to place the answer before selecting the entities. I could have change to a select first, but then it's not so easy to go to the Options idea. For a running area total, I'll probably have to use Pick Entity instead of Select multiple entities ... but maybe not :? ... will look into it and revert back.

When you say "Regioned Object", what exactly do you mean? If it's a REGION then yes, you can obtain the area of this using either my routine or the standard AREA command. If you want to select the entity(ies) which were used to create the REGION ... then no there's no way to do this :cry:. If you mean to select the entities used to create an Associative hatch, then it's possible to write some lisp for that, but much simpler just to select the hatch. If you mean you wish to pick a point like you would by creating a hatch or region ... then a rewrite of my code might do it, but the standard AREA command cant.


I see....thanks a lot for the quick response...i would greatly appreciate a re-written code. Thanks

irneb
2009-04-24, 08:12 AM
OK, here goes. Attached is an entire rewrite of the code (for areas only). Command's still the same DIMAREA. But now asks for you to pick the entities first. Works a lot more like the normal ACAD command AREA, with Addition / Subtraction modes and shows a running total (just ensure you've got at least 3 lines showing in your command line palette). Also allows you to use multiple selections. The settings are also saved to registry so your custom settings (like prefix / suffix / units) stay as per your previous settings (even between sessions and different drawings). Units for Source & Target is also now easier to select than having to remember what the AC code for each unit is, I've added all possible units from the ACAD.UNT file as options (quite a lot, so I had to split it into 3 lists of options). The Place option (default so just hit enter) can place the result in any for of text entity except for table fields.

What I'm still working on:

Placing the result in a table field
Copying the result to clipboard so you can paste it into a spreadsheet.
Editing an already placed area, so you can add / remove entities to / from it.
Do something similar for DIMLENGTH to do perimeter calcs in the same way.
Add a dialog interface to the Settings portion.Give it a try and see if this works for you :)