Here is another play toy.
Code:
;;;=======================[ LengthByLayer.lsp ]=========================
;;; Author: Copyright© 2007 Charles Alan Butler
;;; Version: 1.0 Dec. 26, 2007
;;; Purpose: display the length of objects on layer(s)
;;; Object Types allowed are LINE LWPOLYLINE POLYLINE SPLINE ARC CIRCLE
;;; Returns: -NA
;;;==============================================================
(defun c:LBL()(c:LengthByLayer))
(defun c:LengthByLayer (/ cur_opt entlst ent_allowed filter layfilter len
mode ss tmp total_len txt_opt typ OutStr)
(vl-load-com)
;|
mode
An integer specifying the linear units mode. The mode corresponds to the
values allowed for the AutoCAD system variable lunits and can be one of
the following numbers:
1 Scientific
2 Decimal
3 Engineering (feet and decimal inches)
4 Architectural (feet and fractional inches)
5 Fractional
nil default to DWG settings
|;
(setq mode 4)
(defun put_txt (txt / pt th)
;; Check if the drawing height is set to 0:
(if (setq pt (getpoint "\nPick Text Location..."))
(progn
(if (= 0 (setq th (cdr (assoc 40 (tblsearch "style" (getvar "textstyle"))))))
(setq th (getvar "textsize"))
)
(entmake (list (cons 0 "TEXT")
(cons 1 txt)
(cons 7 (getvar "textstyle"))
(cons 10 pt)
(cons 40 th)
))
)
(prompt "\n*** Text Insert skipped ***")
)
)
(initget "Yes No" )
(setq txt_opt (getkword "\nPut text total in drawing [Yes/No]. <No>"))
(or txt_opt (setq txt_opt "No"))
(initget "Yes No" )
(setq cur_opt (getkword "\nCurrent Space Only? [Yes/No] No for entire DWG. <Yes>"))
(or cur_opt (setq cur_opt "Yes"))
(prompt "\nSelect object(s) for layer filter.")
(if (setq ss (ssget))
(progn
(setq tmp (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss)))
tmp (mapcar '(lambda(x) (cdr(assoc 8 (entget x)))) tmp)
layFilter "")
(mapcar '(lambda(x) (setq layFilter (strcat x "," layFilter))) tmp)
(setq ent_allowed '("LINE" "LWPOLYLINE" "POLYLINE" "SPLINE" "ARC" "CIRCLE"))
(setq Filter (list '(0 . "LINE,LWPOLYLINE,POLYLINE,SPLINE,ARC,CIRCLE") (cons 8 layFilter)))
(if (= cur_opt "Yes")
(setq Filter (cons (cons 410 (getvar "ctab")) Filter))
)
(if (setq ss (ssget "_X" Filter))
(progn
(setq entlst (mapcar 'cadr (ssnamex ss))
total_len 0)
(foreach en entlst
(if (vl-position (setq typ (cdr (assoc 0 (entget en)))) ent_allowed)
(setq len (vlax-curve-getdistatparam en (vlax-curve-getendparam en))
total_len (+ len total_len))
)
)
)
(prompt "\n*** Nothing on that layer with a length. ***")
)
)
)
(and total_len (not (zerop total_len))
(setq OutStr (strcat "Total length is " (if mode (rtos total_len mode)(rtos total_len))))
(princ (strcat "\n" OutStr)) ; display on command line
(if (= txt_opt "Yes") (put_txt OutStr))
)
(princ)
)
(prompt "\nGet Length By Layer loaded, Enter LBL to run")
(princ)