AutoCad 计算所有线段总长度 AutoCad自身没有这个功能,要用代码实现。 ### 方法: 1. 复制下方代码到AutoCad命令栏里后按`回车键`。 2. 命令栏里输入`tlen`后回车,然后选择要计算的所有线段(也可以先选择所有线段后再输入`tlen`命令)。 3. 选择所有线段后按`回车键`就会自动弹出所有线段总长度。 ![屏幕快照 2018-06-22 14.29.02.jpg](https://dt27.cn/usr/uploads/2018/06/4124681958.jpg) ``` ;| TLEN.LSP - Total LENgth of selected objects (c) 1998 Tee Square Graphics |; (defun C:TLEN (/ ss tl n ent itm obj l) (setq ss (ssget) tl 0 n (1- (sslength ss))) (while (>= n 0) (setq ent (entget (setq itm (ssname ss n))) obj (cdr (assoc 0 ent)) l (cond ((= obj "LINE") (distance (cdr (assoc 10 ent))(cdr (assoc 11 ent)))) ((= obj "ARC") (* (cdr (assoc 40 ent)) (if (minusp (setq l (- (cdr (assoc 51 ent)) (cdr (assoc 50 ent))))) (+ pi pi l) l))) ((or (= obj "CIRCLE")(= obj "SPLINE")(= obj "POLYLINE") (= obj "LWPOLYLINE")(= obj "ELLIPSE")) (command "_.area" "_o" itm) (getvar "perimeter")) (T 0)) tl (+ tl l) n (1- n))) (alert (strcat "Total length of selected objects is " (rtos tl))) (princ) ) ```