Field Arithmetic

Function Syntax fieldmath
Current Version 1.0
Download FieldArithmeticV1-0.lsp
View HTML Version FieldArithmeticV1-0.html

Program Description

This program enables the user to perform arithmetic operations (add, subtract, multiply, divide) on numerical text or fields, with the result of the calculation represented using a field expression.

Upon issuing the command syntax fieldmath at the command-line, the program will prompt the user to select a text object with numerical content. At this prompt, the user may select a single-line text object (DText), multiline text (MText), block attribute, multileader (MLeader), or dimension containing numerical content, or choose the Constant option to enter an arbitrary fixed number for use in the calculation.

The program will then prompt the user to choose an operator (addition, subtraction, multiplication, division) to follow the selected or entered numerical value in the calculation. At this prompt, the user is also provided with the option to Undo the last numerical value added to the calculation, or to complete the calculation by choosing the Result option.

Upon selecting the Result option, the program will prompt the user for an insertion point and will then generate a multiline text (MText) object containing a field expression representing the result of the calculation.

Nested Field Expressions

The program also supports nested field expressions: that is, annotation objects which themselves contain field expressions referencing numerical values, as demonstrated by the 'Area' text in the animation below.

When encountering such objects, by default the program will reference the nested field expression directly in the calculation (ignoring any field formatting), as opposed to referencing the text content of the object containing the field expression.

This default behaviour may be toggled by changing the nst parameter within the 'Program Parameters' section of the program source code (see below).


Field Arithmetic Demo

Result Format

The field formatting code indicated at the top of the program source code 'Program Parameters' section may be altered to display the result of the calculation in a desired format:

;;                          Program Parameters                          ;;

        ;; Field formatting for result ("" for no formatting)
        fmt "%lu6%qf1"

        ;; Reference nested fields directly
        nst t


To determine the correct formatting code to be used, perform the following steps:

  • Type FIELD at the AutoCAD command-line and press ENTER to open the Field dialog.
  • Select Objects from the 'Field Category' drop-down menu.
  • Select Formula from the 'Field Names' section.
  • Enter an arbitrary number in the 'Formula' panel and click Evaluate.
  • Configure the formatting options as desired.
  • Click OK and pick a point in the drawing to create a temporary MText Field.
  • Download & load my Field Formatting Code program.
  • Type fieldformat to run the program and select the temporary MText Field created earlier.
  • Following a valid selection, the field formatting code will be printed to the command-line, e.g.:
  • Formatting code: "%lu4%ds44%th39"
  • Copy the formatting code (including the quotation marks) to the program source code where noted:
  • fmt "%lu4%ds44%th39"
  • Save and load the modified program file.

Instructions for Running

Please refer to How to Run an AutoLISP Program.


increase · reset · decrease

Designed & Created by Lee Mac © 2010