Thursday, September 20, 2007

Total Area and Perimeter Calculation Macro

As a continuation to my previous post Total Length Calculation Macro for AutoCAD LT, here is another one to calculate total area and perimeter of selected objects. This macro has a few limitations.

1. You need to end the macro with a cancel (Esc) action.
2. The macro will be terminated upon picking up an object which doesn't have area.
3. Calculates area only by object method. Area calculation by continous picking of points are not supported.

Even after all these limitations, if you are interested, here goes the macro.

*^C^C_Area;O;\setvar;USERR1;$M=$(+,$(getvar,USERR1),$(getvar,AREA));setvar;USERR2;$M=$(+,$(getvar,USERR2),$(getvar,PERIMETER));_modemacro;"Total Area :"$(+,$(getvar,USERR1),$(getvar,AREA))", Total Perimeter :"$(+,$(getvar,USERR2),$(getvar,PERIMETER));

As in the case of length calculation macro, you need to use another macro for clearing the status bar and system variables.

^c^c_modemacro;.;setvar;USERR1;0;;USERR2;0;

9 comments:

Anonymous said...

Hi,
I have a macro for finding the area of an object - *^C^Carea;e;\-mtext;\_none;@1,-1;$m=$(/,$(fix,$(/,$(getvar,area),10000)),100)sqm;;
- the problem with this macro is it only works properly in WCS. Would you be able to fix it so it can work in other UCS? Also it has to work in AutoCAD LT, so no lisp expressions. Hope you can help. TIA.
Kay

Anonymous said...

Hi,
I have a macro for finding the area of an object - *^C^Carea;e;\-mtext;\_none;@1,-1;$m=$(/,$(fix,$(/,$(getvar,area),10000)),100)sqm;;
- the problem with this macro is it only works properly in WCS. Would you be able to fix it so it can work in other UCS? Also it has to work in AutoCAD LT, so no lisp expressions. Hope you can help. TIA.
Kay

har!s said...

Hi Kay,
Could you be a little more specific ? Please tell me exactly what is going wrong with your program.

Anonymous said...

Hi Haris,
When I'm in WCS the mtext (which shows the area in sqm) appears where I click my mouse, but when I'm in a UCS the mtext appears somewhere else depending on the UCS. Hope that explains the problem.

har!s said...

Hi Kay,
Try using TEXT command instead of MTEXT command.

*^C^Carea;e;\Text;\;;$m=$(/,$(fix,$(/,$(getvar,area),10000)),100)sqm;

Hope that solves your promblem.

har!s

Anonymous said...

Hi Haris,
Thanks very much, that did the trick. Would it be too much to ask you to explain the macro or is there any documentation I can look up so I know what's what? Thanks.
Kay

Anonymous said...

Hi.
I use this:
*^C^C-Boundary \;;;Area Object Last;C^C_text m \\ $M=$(rtos,$(/,$(getvar,area),1),2,2) m²;\0.2;;;;

Anonymous said...

Hi har!s,
I've been using your macro for total area for a while and I wonder if there is any way to add a field to the text in the macro itself. In other words, if after I run the macro to find the total area of a Polyline the polyline changes, the area automatically changes. I've been doing it MANUALLY for a while and is quite time consuming.
Thanks for your help,

Juan

Anonymous said...

Hi,
I adapted this macro for my needs and it works great.
Im trying to alter it so I can:
Pick the object that I want the area of, then a second pick to replace an existing piece of text with the new value.

I can get it to pick the text but it wont put the text in.

*^C^Carea;e;\TextEDIT;\;$m=$(/,$(fix,$(/,$(getvar,area),100000)),10)SqM;

thanks
Dave
drichardson@iinet.net.au