多条多段线不连接时计算长度

【如果只是计算多个闭合的图形的总周长】
1,bo命令创建面域
2,uni命令合并面域
3,aa命令点选合并后的面域即可看到周长

【如果需要计算多条不闭合的多段线总长度--包括其中夹杂很多闭合图形的,也可用此法】
1,把以下代码拷贝到记事本,并保存为lsp后缀
2,把该lsp文件拷贝到cad安装目录的support目录下
3,在cad中用appload命令加载该lsp (在每个新窗口中都要重新加载一次)
4,使用LL命令选中全部多段线就可以算出到总长度
5,感谢写这段lsp代码的人!




;;;-----------------------------------------------------
;;;程序名:linelong.LSP
;;;功 能:计算线段和多义线的长度
;;;版 权:(C) copyright 2001.8 by maohong. All Rights Reserved!
;;;-----------------------------------------------------
(defun c:ll( / a n index0 tuyname)
(setq a (ssget))
(setq n (sslength a)) ;求出选择集中的图元数目
(setq index0 0) ;设置计数器
(setq s 0)
(repeat n ;对后面的表达式进行N次计算
(setq tuyname (ssname a index0));返回选择集中由序号指定的图元名
(setq index0 (+ index0 1)) ;计数器加一
(setq ent1 (entget tuyname))
(setq et (length ent1))
(setq et1 et)
(setq index1 0)
(setq test 0)
(setq x2 0)
(setq y2 0)
(setq x1 0 y1 0)
(setq s0 0)
(repeat 2
(setq xy (nth index1 ent1))
;计算line线长
(if (= (cdr xy) "LINE")
(progn
(setq index2 0)
(repeat et1
(setq xy (nth index2 ent1))
(if (= (car xy) 10)
(progn
(setq x1 (nth 1 xy))
(setq y1 (nth 2 xy))
)
)
(if (= (car xy) 11)
(progn
(setq x2 (nth 1 xy))
(setq y2 (nth 2 xy))
)
)
(setq index2 (+ index2 1))
)
(setq s0 (sqrt (+(* (- x2 x1) (- x2 x1)) (* (- y2 y1) (- y2 y1)))))
)
)
;line线计算结束
;计算"LWPOLYLINE"线长
(if (= (cdr xy) "LWPOLYLINE")
(progn
(setq index2 0)
(repeat et1
(setq xy (nth index2 ent1))
(if (= (car xy) 10)
(if (= test 1)
(progn
(setq x2 x1)
(setq y2 y1)
(setq x1 (nth 1 xy))
(setq y1 (nth 2 xy))
(setq s0 (+ s0 (sqrt (+(* (- x2 x1) (- x2 x1)) (* (- y2 y1) (- y2 y

1))))))
)
)
)
(if (= (car xy) 10)
(if (= test 0)
(progn
(setq x1 (nth 1 xy))
(setq y1 (nth 2 xy))
(setq test 1)
)
)
)
(setq index2 (+ index2 1))
)
)
)
;计算"LWPOLYLINE"线结束
(setq index1 (+ index1 1))
)
(print s0)
(setq s (+ s s0))
)
(print )
(princ "总长度:")
(princ s)
(setq a nil)
(princ)
)



相关主题
相关文档
最新文档