江南十笑 发表于 2019-9-11 15:36:29

统计长度和统计面积

;****************************************************测量长度
(defun c:555()
(setq os (getvar "osmode"))
(setvar "osmode" 0)
(setq sum 0 i 0)
(setq ss (ssget))
(repeat (sslength ss)
(setq en (ssname ss i))
(command "lengthen" en "")
(setq l (getvar "perimeter"))
(setq sum (+ sum l)
i (+ i 1))
)
(setvar "osmode" os)
(princ "\n长度之和 = ")
(princsum )
)
;****************************************************测量长度
(defun c:LWW614()
(setq os (getvar "osmode"))
(setvar "osmode" 0)
(setq sum 0 i 0)
(setq ss (ssget))
(repeat (sslength ss)
(setq en (ssname ss i))
(command "lengthen" en "")
(setq l (getvar "perimeter"))
(setq sum (+ sum l)
i (+ i 1))
)
(setvar "osmode" os)
(princ "\n长度之和 = ")
(princsum )
)

;****************************************************面积求和
(defun c:666 (/ olderr oldcmdecho errexit undox restore ss1 nr en tot_area)
(defun errexit (s)
(restore)
)

(defun undox ()
(command "._undo" "_E")
(setvar "cmdecho" oldcmdecho)
(setq *error* olderr)
(princ)
)

(setq olderr *error*
restore undox
*error* errexit
)
(setq oldcmdecho (getvar "cmdecho"))
(setvar "cmdecho" 0)
(command "._UNDO" "_BE")
(if (setq ss1 (ssget '((-4 . "<OR")
(0 . "POLYLINE")
(0 . "LWPOLYLINE")
(0 . "CIRCLE")
(0 . "ELLIPSE")
(0 . "SPLINE")
(0 . "REGION")
(-4 . "OR>")
)
)
)
(progn
(setq nr 0)
(setq tot_area 0.0)
(setq en (ssname ss1 nr))
(while en
(command "._area" "_O" en)
(setq tot_area (+ tot_area (getvar "area")))
(setq nr (1+ nr))
(setq en (ssname ss1 nr))
)
(princ "\n面积之和 = ")
(princ tot_area)
)
)
(restore)
)

代码如上为何统计长度时,最终计算结果重复显示?如何修改?统计面积的结果为科学计数法?怎么修改?


Andyhon 发表于 2019-9-11 16:37:05

Ref: Rtos 函数

xyp1964 发表于 2019-9-11 21:38:25

(princ tot_area) → (princ (rtos tot_area 2 3))

yubihai 发表于 2019-11-26 10:45:42

代码中间出现的握嘴笑和哭脸是几个意思啊

zhangrunze 发表于 2024-3-29 15:07:25

选长度会报错~
命令: 555
选择对象: 找到 1 个
选择对象: 找到 1 个,总计 2 个
选择对象:
当前长度: 4061.6291
需要数值距离、两点或选项关键字。
Error: 函数已取消
指定总长度或 [角度(A)] <156.0092>: *取消*
命令: *取消*
页: [1]
查看完整版本: 统计长度和统计面积