You are here:

AutoCAD/Macro to insert area field

Advertisement


Question
I need to measure areas of many closed polygons in the course of calculating quotations for concrete slabs.
My initial work flow was to select the object, read the area from the properties list, create a text object and type the value.
My units are millimeters but I need to show the area in Square Meters. The simple calculation is error prone.
I wrote a simple macro to select the polygon and display the area in the command summary.
I don't know how to retrieve the value for inserting into text, and the units are Square mm instead of Sq Mtrs.
I have now used text fields, and find that very useful.
However, the procedure is time consuming and I would like to make it a "one click" operation.
I have limited knowledge of writing macros, but do not know how to process the Field Editor portion.
Is there a reasonably workable solution?
Below is my work flow for inserting the area field.


Command: -TEXT
Current text style:  "Standard"  Text height:  500.0000  Annotative:  No
Specify start point of text or [Justify/Style]:
Specify rotation angle of text <0>:
Enter text:  sq mtr

Command: _ddedit

Place cursor at beginning of text
Right click on text and select "Insert filed"
In the field edit window:
Choose category "Objects" and click "Object"
Click "Select Object"
In the drawing click on a closed polyline object
Under Properties select "Area"
Under Format select "Decimal"
Under Precision select "0.00"
Click Additional Format
Under conversion factor enter 0.000001
Click OK
The displayed Field expression is:

%<AcObjProp.16.2 Object(%<_ObjId 2129689640>%).Area f "%lu2%pr2%ct8[1e-006]">%

Click OK

The value is displayed on a grey background

Answer
I experimented with this for a couple of hours this morning.  Do you need the area to automatically update if the area changes?  If so, then you need to use fields.
You can place them directly with the field command, which may be a little quicker.

If you do not need them to auto-update, then placing the area into text and putting it on the drawing is a fairly simple and common program, I came up with several examples to choose from with a google search for "autolisp area text".  This one seems decent: http://www.jefferypsanders.com/autolisp_examp.html#GetArea.lsp

There are different features to some of the routines available, notably that some accumulate areas from multiple polygons and then insert it into text.  You'll need to add one line of code to change from mm to M, let me know if you need help with that.

AutoCAD

All Answers


Answers by Expert:


Ask Experts

Volunteer


Scott Cook

Expertise

I`ve been using AutoCAD since 1987 and programming AutoLISP nearly as long. I can answer questions about programming AutoCAD (except ARX) and production enhancement techniques. I cannot answer questions about AutoCAD crashes or DWG corruption. AutoCAD PROGRAMMING (menus, lisp) related questions only!

Experience

Since 1987. Author of Plot2000 software for for AutoCAD, http://www.plot2000.com. PROGRAMMING QUESTIONS ONLY PLEASE. Questions that are NOT related to programming or AutoCAD customization (menus and lisp only please) are outside the scope of my volunteer services and will NOT BE ANSWERED.

©2016 About.com. All rights reserved.