• Blog posts

    Bio

    By Dennis Collin

    AutoCAD_Tip_-_Using_AutoLIsp_to_add_area_as_a_field_-_1.PNG

    I have posted a series of articles in the past as to how text fields could be used to show areas of such objects as hatches or polylines:

    AutoCAD Areas - Part 1, AutoCAD Areas - Part 2, AutoCAD Areas - Part 3

    Using AutoLisp can make this process a little easier, especially when needing to format the units to be different from the measured linear units i.e. in a metric building plan, lengths might be measured in millimetres, but areas might be measured in square metres!

    The formatting can be set in the code as we will see later.

    There are many useful Lisp routines that will calculate areas but one of my favourite sources is Lee Mac’s Lisp Programming site where the Lisp routine can be downloaded.

    http://www.lee-mac.com/areastofield.html

    Once loaded via Appload, the program will create an MText object containing a Field Expression referencing the area, or sum of areas, of one or more selected objects.

    AutoCAD_Tip_-_Using_AutoLIsp_to_add_area_as_a_field_-_2.PNG

    The command can be executed by using the keystroke ‘A2F’ on the command prompt.  The application will prompt the user to select objects for which to retrieve the area for single or multiple objects as desired.

    The user can locate the text field anywhere in the drawing but, if the specified point resides within an AutoCAD table cell, the program will populate the table cell with the appropriate Field Expression.

    The Field will display a total of the areas of the selected objects with the default formatting.

    This formatting code may be altered to suit specified requirement. To achieve this, open the Lisp routine in an application like Notepad and locate the following code with the remark Field Formatting.

    AutoCAD_Tip_-_Using_AutoLIsp_to_add_area_as_a_field_-_3.PNG

    Replace the highlighted red text string with the following if you want to show the area in square metres but length in millimetres.

    %lu2%pr1%ct8[1.000000000000000E-006]

    (Unit Type, Precision, Conversion to Square Metres)

    AutoCAD_Tip_-_Using_AutoLIsp_to_add_area_as_a_field_-_4.PNG

    With a slight amendment to the routine, a prefix like Area and a metre squared suffix could be added for clarity.

    This particular routine will work with AutoCAD 2015 or later.