如何快速计算cad中多条多段线的总长
3个回答
2016-12-26 · 知道合伙人软件行家
关注
展开全部
用插件计算。
很多插件都有计算长度功能,比如【天正】【超越工具集】等。
autolisp代码如下:
(defun c:TE ( / &k1 &kw1 &ss1 cd1 i x)
(setvar "cmdecho" 0)
(setvar "blipmode" 0)
(if (null vlax-dump-object) (vl-load-com) )
(princ "\n请选择曲线")
(if (setq &kw1 (ssget '((0 . "*LINE,ARC,CIRCLE,HELIX,ELLIPSE"))))
(progn
(setq i -1.0 &ss1 '())
(while (setq &k1 (ssname &kw1 (setq i (1+ i))))
;(vla-put-color (vlax-ename->vla-object &k1) 252)
(setq &ss1 (cons &k1 &ss1))
)
(setq &ss1 (mapcar '(lambda (X) (* 0.001 (vlax-curve-getDistAtParam x (vlax-curve-getEndParam x)))) &ss1))
(setq cd1 (apply '+ &ss1))
(setq &ss1 (apply 'strcat (cdr (apply 'append (mapcar '(lambda (x) (list "+" (rtos x))) &ss1)))))
(setq &ss1 (strcat "(" &ss1 ")"))
(s1611151 &kw1
(list (strcat "\n" (rtos i 2 0) "条曲线计算公式为:" &ss1) (strcat "\n" (rtos i 2 0) "条曲线总长度:" (rtos cd1) "米"))
)
)
)
(princ)
)
(defun s1611151 (&kw1 str / &k1 &kw1 a1 a2 ss1)
(setq ss1 '() a1 0.0 i 0.0)
(while (setq &k1 (ssname &kw1 0))
(setq &kw1 (ssdel &k1 &kw1))
(if (and (vlax-curve-isClosed &k1);如果对象是闭合对象
(setq &k1 (vlax-ename->vla-object &k1));转换为vlax对象
(null (vl-catch-all-error-p (setq a2 (vl-catch-all-apply 'vla-get-area (list &k1)))))
);计算面积
(progn
(setq a2 (* 0.000001 a2) i (1+ i))
(setq a1 (+ a1 a2));总面积
(setq a2 (rtos a2))
(if (car ss1)
(setq ss1 (append ss1 (list "+" a2)));计算公式
(setq ss1 (cons a2 ss1))
)
)
)
);while
(if (> a1 0.0)
(progn
(princ (car str))
(princ (strcat "\n" (rtos i 2 0) "个封闭对象面积计算公式为:(" (apply 'strcat ss1) ")"));显示计算公式
(princ (cadr str))
(princ (strcat ";" (rtos i 2 0) "个封闭对象总面积:" (rtos a1) " 平方米"))
)
(princ (apply 'strcat str))
)
)
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询