- 积分
- 28877
- 明经币
- 个
- 注册时间
- 2013-1-25
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
发表于 2019-4-28 05:04:29
|
显示全部楼层
;;;;;程序源码 “飞鸟集”,修改:尘缘一生 2019-4-28
;;;关于对于面积求和和长度求和,还是有很多用途,在这里写一个lisp程序。加载运行am
;;;选择你要求和的物体,可以是line ,circle,arc ,ellipse ,spline, polyline,mline等,算出面积和长度。
;;; 【不用指定位置和高度,用你CAD整体比例系数控制】,用文字标注出来,并跟随鼠标定位
(defun C:am (/ s text1 text2 ss l i totalarea ename obj insertpt insertpt1)
(if (setq ss (ssget))
(progn
(vl-load-com)
(setq modelspace (vla-get-Modelspace (vla-get-activeDocument (vlax-get-acad-object))))
(setq l (sslength ss) i 0 totalarea 0 totlength 0)
(repeat l
(setq ename (ssname ss i))
(setq obj (vlax-ename->vla-object ename))
(if (vlax-property-available-p obj "area")
(setq totalarea (+ (vlax-get-property obj 'area) totalarea))
)
(if (= (cdr (assoc 0 (entget ename))) "MLINE")
(setq totlength (+ totlength (ml-length ename)))
(setq totlength (+ totlength (vlax-curve-getdistatparam ename (vlax-curve-getendparam ename))))
)
(setq i (1+ i))
)
(setq text1 (strcat "总面积为: " (rtos totalarea 2 4) "平方单位")
text2 (strcat "总长度为: " (rtos totlength 2 4) "单位")
)
(setq insertpt (nth 1(grread 5)))
(setq insertpt1 (polar insertpt (* 1.5 pi) (* (getvar "DIMSCALE") 7.0)))
(entmake (list '(0 . "TEXT") (cons 1 text1) (cons 8 "PUB_TEXT") (cons 10 insertpt) (cons 40 (* (getvar "DIMSCALE") 5.0))))
(setq s(ssadd))
(ssadd (entlast) s)
(entmake (list '(0 . "TEXT") (cons 1 text2) (cons 8 "PUB_TEXT") (cons 10 insertpt1) (cons 40 (* (getvar "DIMSCALE") 5.0))))
(ssadd (entlast) s)
(command "MOVE" s "" insertpt)
)
)
)
(defun ml-length (ename / j d ptlist)
(foreach n (entget ename)
(if (= (car n) 11)
(setq ptlist (cons (cdr n) ptlist))
)
)
(reverse ptlist)
(setq j 0 d 0)
(repeat (1- (length ptlist))
(setq d (+ d (distance (nth j ptlist) (nth (1+ j) ptlist))))
(setq j (1+ j))
)
d
) |
|