Length Field

Function Syntax LF
Current Version 1.1
Download LengthFieldV1-1.lsp
View HTML Version LengthFieldV1-1.html
Donate

Program Description

This program allows a user to generate a field expression referencing the length/perimeter/circumference of one or more selected objects. In the case of selecting multiple objects, the field expression will reference the sum of the lengths of all objects in the selection.

The user may opt to specify a point at which to create a new multiline text object housing the field expression, pick a table cell in which the field should be inserted, or select an existing single-line text, multiline text, multileader, or attribute to be populated with the field expression.

Upon issuing the command syntax LF (Length Field) at the AutoCAD command-line, the program first prompts the user to make a selection of objects for which to return the total length.

At this prompt, the user may select any number of Arcs, Circles, Lines, 2D Polylines (light or heavy), or 3D Polylines.

The user is then prompted to specify a point or table cell to insert a field expression referencing the summation of the lengths of the selected objects.

At this prompt, the user may also choose the Object option in order to populate the content of an existing annotation object with the field expression.

Upon choosing this option, the user may select any single-line text (DText), multiline text (MText), single-line or multiline attribute, attributed block, or multileader (MLeader) with either multiline text or attributed block content.

If the user selects an attributed block or attributed multileader with more than one attribute, the user is presented with a dialog interface listing the available attributes, and is prompted to select a destination for the field expression.

The user may optionally predefine the target block/multileader attribute by specifying the attribute tag where noted at the top of the program source code.

The resulting field expression will display the sum of the lengths of the selected objects, formatted using the field formatting code specified at the top of the program.

Demonstration

Length Field Demo?

Length Format

The field formatting code indicated at the top of the program source code 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 (or equivalent property for Arcs & Circles).
  • 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.

textsize

increase · reset · decrease

Designed & Created by Lee Mac © 2010