Length at Midpoint

Function Syntax midlen
Current Version 1.1
Download MidLenV1-1.lsp
View HTML Version MidLenV1-1.html

Program Description

This program automatically generates multiline text (MText) objects positioned over the midpoint of every object in a user selection, with each item of MText containing a field expression referencing the length of the object.

Upon issuing the command syntax midlen at the AutoCAD command-line, the program will prompt the user for a selection of objects for which to display the length. Following a valid selection, the program will proceed to generate an MText object located at the midpoint of each selected object, and containing a field expression referencing the length of the object.

The program is compatible for use with Arcs, Circles, Lines, LWPolylines, 2D & 3D Polylines, and will perform successfully with objects constructed in any UCS plane, and under all active UCS & View settings.

The program will generate MText objects positioned directly over the midpoint of each object, and aligned with the object whilst preserving text readability. The MText will have a background mask enabled and will use the active Text Style and Text Height settings at the time of running the program.


Length at Midpoint Demo

In the above demonstration, the FIELDDISPLAY system variable is set to 0.

Length Format

The field formatting code indicated at the top of the program source code (line 26) may be altered to display the length in a desired format:

(setq fmt "%lu6") ;; Field Formatting

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 Object from the 'Field Names' section.
  • Select an object (with length) from the drawing by clicking the object selection button adjacent to the 'Object Type' box.
  • Select the Length property from the 'Property' panel.
  • 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:
  • (setq fmt "%lu4%ds44%th39") ;; Field Formatting
  • 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