1. ;==============================================================================
;Function: to calculate the total length of the selected objects (line, curve or arc)
;==============================================================================
(defun c:ts() ;the command "ts"
(vl-load-com) ;load the microsoft activeX support
(setq tleng 0) ;set the initial value of variant "tleng"
(setq s (ssget)) ;pick up the measured objects
(setq n (sslength s)) ;count the selection
(setq index (- n 1)) ;set the loop index
(setq lens (list 0)) ;construct the object length list
(repeat n ;start the loop to go through the selection
(setq ent (ssname s index)) ;select the item in the selection
(setq index (- index 1)) ;prepare for the next item with variant index
(setq curve-obj (vlax-ename->vla-object ent)) ;convert the item to activeX object to calculate the length
(setq leng (vlax-curve-getDistAtParam ;get the length and store it to variant leng
curve-obj
(vlax-curve-getEndParam curve-obj)
)
)
(setq lens (append lens (list leng))) ;send the length to list "lens"
(setq tleng (+ tleng leng)) ;add the length to variant "tleng"
(princ leng) ;print the current object's length
(princ "n") ;return in the AutoCAD command line
)
(setq lens (vl-sort lens '<)) ;sort the list "lens" in ascending order
(princ (strcat "n 总共计算" ;print the total length and the maximum and
;minimum length of the selected objects
(itoa n) "个对象,n 总长度为 "
(rtos tleng 2 6)
"n 平均值为 "
(rtos (/ tleng n) 2 6)
"n 最小值为 "
(rtos (cadr lens) 2 6)
"n 最大值为 "
(rtos (last lens) 2 6)
)
)
(princ)
)