AutoCAD/Macro to insert area field
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.
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
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
The displayed Field expression is:
%<AcObjProp.16.2 Object(%<_ObjId 2129689640>%).Area f "%lu2%pr2%ct8[1e-006]">%
The value is displayed on a grey background
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.