Create code that can determine the length of polyline segments and fit into the drawing area above the segments.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
We need a code in AutoLisp for Autosad 2023 that can calculate the length of all polyline segments and write them above the segments in the drawing area. This is the code for the segment.
Here is the code for the segment.
(defun c:Lin_di ()
(while (setq obj (car (entsel "\nSelect a segment (or press Enter to exit): ")))
(setq startPoint (cdr (assoc 10 (entget obj))))
(setq endPoint (cdr (assoc 11 (entget obj))))
(setq length (distance startPoint endPoint))
(setq roundedLength (fix length)) ; Round the length to a whole number
(setq textPoint (polar startPoint (angle startPoint endPoint) (/ length 2.0)))
(setq textString (rtos roundedLength 2 0)) ; Rounded length as an integer
(command "_text" textPoint "8" "0" textString)
(princ "\nAdded an inscription with a rounded segment length.")
)
(princ "\nExiting the mode of measuring the length of segments.")
(princ)
)