Autocad Lisp Routine For Calculating Total Length Of Selected Objects

The provided source materials describe a LISP routine named TLEN.lsp, designed for AutoCAD and BricsCAD users to calculate the total length of selected drawing entities. This utility processes a user-selected set of objects, including lines, arcs, circles, splines, polylines, lwpolylines, and ellipses, and returns the sum of their lengths. The routine originated from Tee Square Graphics in 1998 and remains relevant for users needing quick quantitative measurements of geometry within a drawing file. The documentation outlines the technical functionality of the code, instructions for implementation within the AutoCAD environment, and options for automating its loading process.

Functionality and Supported Object Types

The core purpose of the TLEN.lsp routine is to automate the calculation of total linear distance within a selection set. According to the documentation, the program operates by iterating through selected objects, identifying their entity types, and applying specific geometric calculations based on the object's properties.

The supported object types include: - Lines: Calculated by measuring the distance between the start point (coordinate 10) and end point (coordinate 11). - Arcs: Calculated using the radius (coordinate 40) and the angular extent. The code accounts for potential negative angular values by normalizing the start and end angles (coordinates 50 and 51) to ensure a positive arc length. - Circles, Splines, Polylines, LWPolylines, and Ellipses: The routine identifies these entities and calculates their length using standard geometric properties associated with each type.

The process involves the ssget command to allow the user to select objects interactively. The routine then loops through the selection set, retrieves entity data using entget, and sums the calculated lengths into a total variable (tl). The final result is typically displayed in the AutoCAD command line.

Installation and Loading Procedures

Source materials provide specific instructions for installing and loading the TLEN.lsp file into an AutoCAD session. The process utilizes the AutoCAD Application Load dialog.

Locating the File: Users must first obtain the tlen.lsp file. The source references a historical link to www.turvill.com, though an archived version is suggested as a point of reference. Once downloaded, the user must note the file location on their computer.

Loading via Application Load Dialog: 1. Open the Application Load dialog. This can be accessed by typing APPLOAD in the command line or navigating through the menu by selecting Tools and then Load Application. 2. Navigate to the folder containing the tlen.lsp file. 3. Ensure the file type filter is set to accept .lsp or .vlx files. 4. Select the tlen.lsp file. 5. Click the Load button. 6. Upon successful loading, AutoCAD should display a confirmation message in the command line, such as "TLEN.LSP loaded."

Direct Command Line Input: Alternatively, the source suggests a method for immediate use without permanent loading: 1. Open the file tlen.lsp in a text editor. 2. Copy the entire block of code, from (defun to the closing parenthesis. 3. Paste the code directly into the AutoCAD command line and press Enter.

Usage Instructions

Once loaded, the routine is executed by typing the command TLEN into the AutoCAD command line. The program prompts the user to select objects. After the selection is made and confirmed (by pressing Enter), the program calculates the total length and displays the result.

Automation via Startup Suite

For users who require frequent access to the TLEN routine, the documentation mentions an optional step to automate the loading process. This ensures the script is available every time AutoCAD starts without manual intervention.

Adding to Startup Suite: 1. Open the Application Load (APPLOAD) dialog. 2. Locate the Startup Suite section within the dialog. 3. Click the Contents button. 4. In the Startup Suite contents window, click Add. 5. Navigate to and select the tlen.lsp file. 6. Click Open to add it to the suite.

Once added to the Startup Suite, the tlen.lsp file will load automatically upon launching the software.

Related Utilities

While the primary focus of the source material is the TLEN.lsp routine, the documentation also references related AutoCAD utilities by Lee Mac. One such utility is BlockCounter, which is capable of recording quantities of standard or dynamic blocks within a drawing. This program offers similar output options to TLEN, including displaying results at the command line, writing to Text or CSV files, or populating an AutoCAD Table. Other referenced utilities include tools for modifying TIN surfaces, drawing grids with coordinates, and transforming Excel spreadsheet data into CAD entities.

Source Reliability and Versioning

The information provided in the source material is derived from a mix of archived web pages, forum conversations, and code repositories. The primary code example is attributed to "Tee Square Graphics" from 1998, indicating that this is a legacy routine. Users should be aware that while the core logic for calculating lengths of basic entities (lines, arcs) is standard, compatibility with newer AutoCAD object types or complex custom entities may vary depending on the specific version of the routine found. The source material does not provide a specific version number for the TLEN.lsp file beyond the 1998 attribution.

Conclusion

The TLEN.lsp routine provides a functional method for calculating the total length of selected objects in AutoCAD and BricsCAD. It supports a variety of standard geometric entities and can be loaded either temporarily for immediate use or permanently via the Startup Suite for recurring access. The instructions provided in the source materials guide users through the necessary steps to locate, load, and execute the routine within the AutoCAD environment.

Sources

  1. Forum Conversation on Autodesk Community
  2. Archived Link to TLEN.lsp Code
  3. GitHub Repository: Autocad-lisp
  4. Scribd Document: TLEN
  5. Canadacad.ca: How to Load TLEN in AutoCAD