Total Length & Area Programs

Here I offer a couple of simple programs to display the total length or area of selected objects at the AutoCAD command line.

I realise that this functionality does already exist in most versions of AutoCAD, however these programs may offer both a faster approach to retrieving the result and are furthermore a good learning aid for those aiming to write their own programs of a similar nature.

Total Length

Function Syntax tlen
Current Version 1.1

This program displays the total length of selected objects at the command line.

The units and precision format of the printed result is dependent upon the settings of the LUNITS & LUPREC system variables respectively.

Select all
;;--------------------=={ Total Length }==--------------------;;
;;                                                            ;;
;;  Displays the total length of selected objects at the      ;;
;;  command line. The units and precision format of the       ;;
;;  printed result is dependent upon the settings of the      ;;
;;  LUNITS & LUPREC system variables respectively.            ;;
;;------------------------------------------------------------;;
;;  Author: Lee Mac, Copyright © 2013 - www.lee-mac.com       ;;
;;------------------------------------------------------------;;

(defun c:tlen ( / e i l s )
    (if (setq s
            (ssget
               '(   (0 . "ARC,CIRCLE,ELLIPSE,LINE,*POLYLINE,SPLINE")
                    (-4 . "<NOT")
                        (-4 . "<AND")
                            (0 . "POLYLINE") (-4 . "&") (70 . 80)
                        (-4 . "AND>")
                    (-4 . "NOT>")
                )
            )
        )
        (progn
            (setq l 0.0)
            (repeat (setq i (sslength s))
                (setq e (ssname s (setq i (1- i)))
                      l (+ l (vlax-curve-getdistatparam e (vlax-curve-getendparam e)))
                )
            )
            (princ "\nTotal Length: ")
            (princ (rtos l))
        )
    )
    (princ)
)
(vl-load-com) (princ)

Total Area

Function Syntax tarea
Current Version 1.1

This program displays the total area of selected objects at the command line.

The precision of the printed result is dependent on the setting of the LUPREC system variable.

Select all
;;---------------------=={ Total Area }==---------------------;;
;;                                                            ;;
;;  Displays the total area of selected objects at the        ;;
;;  command line. The precision of the printed result is      ;;
;;  dependent on the setting of the LUPREC system variable.   ;;
;;------------------------------------------------------------;;
;;  Author: Lee Mac, Copyright © 2013 - www.lee-mac.com       ;;
;;------------------------------------------------------------;;

(defun c:tarea ( / a i s )
    (if (setq s
            (ssget
               '(   (0 . "CIRCLE,ELLIPSE,*POLYLINE,SPLINE")
                    (-4 . "<NOT")
                        (-4 . "<AND")
                            (0 . "POLYLINE") (-4 . "&") (70 . 80)
                        (-4 . "AND>")
                    (-4 . "NOT>")
                )
            )
        )
        (progn
            (setq a 0.0)
            (repeat (setq i (sslength s))
                (setq a (+ a (vlax-curve-getarea (ssname s (setq i (1- i))))))
            )
            (princ "\nTotal Area: ")
            (princ (rtos a 2))
        )
    )
    (princ)
)
(vl-load-com) (princ)

Instructions for Running

Please refer to How to Run an AutoLISP Program.

textsize

increase · reset · decrease

Designed & Created by Lee Mac © 2010