Length Field to Attribute

Function Syntax L2A
Current Version 1.0
Download LengthFieldToAttributeV1-0.lsp
View HTML Version LengthFieldToAttributeV1-0.html
Donate

Program Description

This program allows a user to populate a selected attribute with a Field Expression referencing the length or perimeter, (or sum of lengths or perimeters), of one or more objects.

Upon issuing the command syntax L2A the user is prompted to make a selection of objects for which to retrieve the length; if more than one object is selected, the cumulative length for all objects will be displayed by the resultant Field Expression.

Following object selection, the user is then prompted to select either an attributed block or an attribute in which to house the Field Expression. If the user directly selects an attribute, the attribute value will be populated with the Field Expression; if the user selects an attributed block containing more than one attribute, the program will prompt the user via a dialog interface to choose an attribute tag to be populated with the Field Expression.

An optional attribute tag parameter specified at the top of the program source code also allows the user to predefine the attribute tag that is to be populated with the Field Expression. If this parameter holds a valid string value, the program will automatically populate such attribute following selection of an attributed block containing an attribute with a matching tag name.

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

Length Format

The field formatting code indicated at the top of the program source code (line 27) 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