- 积分
- 18013
- 明经币
- 个
- 注册时间
- 2007-1-6
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
楼主 |
发表于 2021-6-4 08:16:49
|
显示全部楼层
;修改了一下,增加了标注的相应图层及文字样式
;;============================
;;长度面积统计: T
;;计量结算标注: TT
;;长度统计: TG
;;面积统计: GT
;;=============================
;长度面积统计,选择测算数据不能局部函数,无法擦除
(defun caleachone();测量当前元素长度与面积
(setq dis (vlax-curve-getDistAtParam obj (vlax-curve-getEndParam obj)))
(setq area (vl-catch-all-apply 'vlax-curve-getArea (list obj)))
)
(defun Total-count(/ ename i n obj);长度面积统计
(vl-load-com)
(setvar "cmdecho" 0)
(setq
n (sslength ss)
i 0
totalarea 0
totlength 0
)
(repeat n
(setq ename (ssname ss i))
(setq obj (vlax-ename->vla-object ename))
(caleachone)
(setq totlength (+ dis totlength))
(setq totalarea (+ area totalarea))
(setq i (1+ i))
(if (or (= L 1)(= S 1))
(princ (strcat "\n第" (itoa i) "个图元"))
)
(if (= L 1)
(princ (strcat ", 长度=" (rtos dis 2 3) "mm"))
)
(if (= S 1)
(if (/= area 0.0)
(princ (strcat ", 面积=" (rtos area 2 3) "mm2"))
(princ (strcat ", 无面积属性!"))
)
)
)
(princ "\n****默认绘图比例1:1,以mm为单位****")
(princ (strcat "\n>>>>>共统计了" (itoa n) "个"))
(setq totlength (strcat ",累计长度=" (rtos (/ totlength 1e3) 2 3) "m"))
(setq totalarea (strcat ",累计面积=" (rtos (/ totalarea 1e6) 2 3) "m2"))
(setvar "cmdecho" 1)
(princ)
)
(defun c:T(/ l s ss);长度面积统计
(princ "-->长度与面积统计")
(setq ss (ssget '((0 . "CIRCLE,ELLIPSE,*POLYLINE,SPLINE,ARC,LINE"))))
(setq L 0 S 0)
(Total-count)
(princ(strcat totlength totalarea))
(princ)
)
(defun c:tg(/ l s ss);长度统计
(princ "-->长度统计")
(setq ss (ssget '((0 . "CIRCLE,ELLIPSE,*POLYLINE,SPLINE,ARC,LINE"))))
(setq L 1 S 0)
(Total-count)
(princ totlength)
(princ)
)
(defun c:gt(/ l s ss);面积统计
(princ "-->面积统计")
(setq ss (ssget '((0 . "CIRCLE,ELLIPSE,*POLYLINE"))))
(setq L 0 S 1)
(Total-count)
(princ totalarea)
(princ)
)
;周长与面积图形标注
(defun c:tt (/ calname caltextlabel ename htext_max htext_mini i n obj olay oldstyle pt pt2 ss thestring)
(defun caltextlabel(thestring Htext Value / *doc* textobj)
(setq *doc* (vla-get-ActiveDocument (vlax-get-acad-object)))
(setq textobj (vla-addtext
(vla-get-Modelspace *doc*)
thestring
(vlax-3d-point pt)
Htext
)
)
(vla-put-Alignment textobj Value)
(vla-put-TextAlignmentPoint textobj pt2)
)
(vl-load-com)
(setvar "cmdecho" 0)
(setq ss (ssget '((0 . "CIRCLE,ELLIPSE,*POLYLINE,SPLINE,ARC,LINE"))))
(setq
n (sslength ss)
i 0
)
;算量辅助标注名
(setq calname "LB_算量辅助标注")
;创建沿线文字专用样式
(setq olay (getvar "clayer"))
(if (= (tblobjname "layer" calname) nil)
(vl-cmdf "Layer" "new" calname "color" "63" calname "" )
)
(setvar "clayer" calname)
;创建沿线文字专用样式
(setq oldstyle (getvar "TEXTSTYLE"));当前文字样式
(if (= (tblobjname "STYLE" calname) nil)
(vl-cmdf "style" calname "tssdeng.shx,hztxt.shx" "0.0" "0.7" "" "" "" "")
(setvar "TEXTSTYLE" calname)
)
;设置标注字体高度
(setq
Htext_max 120
Htext_mini 75
)
;开始计算并标注
(if ss
(progn
(repeat n
(setq ename (ssname ss i))
(setq obj (vlax-ename->vla-object ename))
(vla-GetBoundingBox obj 'minpt 'maxpt)
(setq pt (mapcar '(lambda (x) (/ x 2.0))
(mapcar '+
(vlax-safearray->list minpt)
(vlax-safearray->list maxpt)
)
)
)
(setq pt2 (vlax-make-safearray vlax-vbDouble '(0 . 2)))
(vlax-safearray-fill pt2 pt)
(caleachone)
(cond
((> (/ area 1000000) 0.3)
(setq thestring (strcat "S=" (rtos (/ area 1000000) 2 2) "m2"))
(caltextlabel thestring Htext_max acAlignmentBottomCenter)
(setq thestring (strcat "L=" (rtos (/ dis 1e3) 2 2) "m"))
(caltextlabel thestring Htext_max acAlignmentTopCenter)
)
((> (/ area 1000000) 0)
(setq thestring (strcat "S=" (rtos (/ area 1000000) 2 2) "m2"))
(caltextlabel thestring Htext_mini acAlignmentBottomCenter)
(setq thestring (strcat "L=" (rtos (/ dis 1e3) 2 2) "m"))
(caltextlabel thestring Htext_mini acAlignmentTopCenter)
)
((= (/ area 1000000) 0)
(setq thestring (strcat "L=" (rtos (/ dis 1e3) 2 2) "m"))
(caltextlabel thestring Htext_max acAlignmentMiddleCenter)
)
(t nil)
)
(setq i (1+ i))
)
)
)
(setvar "clayer" olay)
(setvar "TEXTSTYLE" oldstyle)
(setvar "cmdecho" 1)
(princ "\n****默认绘图比例1:1,以mm为单位,实际如果不同,则标注结果错误!!!****")
(princ)
)
(princ)
|
|