- 积分
- 5070
- 明经币
- 个
- 注册时间
- 2013-1-8
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
存在问题:1程序比较扎乱,不简练。2面积标注与统计(实际上是求和)要选2次。请求修改为一次选择即可完成面积标注与统计标注,谢谢!程序如下:
;;;面积计算并统计
(defun c:mjjstj(/ ACADDOC ACADSPC OBJAREA OBJLLPOINT OBJRUPOINT SELECTIONSET TEXTBASEPOINT TEXTHEIGHT TEXTINDEX TEXTOBJ)
(vl-load-com)
(setq AcadDoc (vla-get-activedocument (vlax-get-acad-object)))
(if (= (getvar "TILEMODE") 1)(setq AcadSpc (vla-get-modelspace AcadDoc))(setq AcadSpc (vla-get-paperspace AcadDoc)))
(setq TextHeight (getdist "\n输入标注文字高度:")
Textbh (getstring "\n输入编号前缀:")
TextIndex 1
)
(setq f (getfiled "指定输出文件路径" "" "xls" 1) f (open f "a"));;;指定输出文件路径
(write-line "编号\t面积(㎡)" f)
(ssget '((0 . "CIRCLE,LWPOLYLINE,ELLIPSE")))
(command "layer" "M" "计算面积" "C" "6" "" "LT" "CONTINUOUS" "" "");设置一个标注图层
(command "style" "tukou" "黑体" "0" "0.7" "0" "" "")
(setvar"dimzin"0);;保留小数位数时如果位数不足可以补零
(setq Selectionset (vla-get-activeselectionset AcadDoc))
(if (and TextHeight Selectionset TextIndex)
(vlax-for Obj Selectionset
(setq ObjArea (vla-get-area obj)
ObjLlPoint nil
ObjRuPoint nil
)
(vla-GetBoundingBox Obj 'ObjLlPoint 'ObjRuPoint)
(setq TextBasePoint (mapcar '(lambda(x y) (/ (+ x y) 2)) (vlax-safearray->list ObjLlPoint)(vlax-safearray->list ObjRuPoint))
TextObj (vla-addtext AcadSpc (strcat Textbh (itoa TextIndex) "=" (rtos (/ ObjArea 1)2 2) "㎡") (vlax-3d-point TextBasePoint) TextHeight)
)
(write-line (strcat (strcat Textbh (itoa TextIndex)) "\t" (rtos (/ ObjArea 1)2 2) ) f)
(vla-put-alignment TextObj acAlignmentCenter)
(vla-put-TextAlignmentPoint TextObj (vlax-3d-point TextBasePoint))
(setq TextIndex (1+ TextIndex))
)
)
(close f)
(princ "面积标注完毕,要统计请选择统计对象,不统计请按esc")
(if (setq ss (ssget '((0 . "CIRCLE,LWPOLYLINE,ELLIPSE"))))
(progn
(vl-load-com)
(setq l (sslength ss) k 0 tarea 0 )
(repeat l
(setq ename (ssname ss k))
(setq obj (vlax-ename->vla-object ename))
(if (vlax-property-available-p obj "area")
(setq tarea (+ (vlax-get-property obj 'area) tarea))
)
(setq k (1+ k))
)
(setq insPt0 (getpoint "\n请输入文字插入点: "))
(setq tarea (/ tarea 1))
(setq bb (strcat Textbh"="Textbh"1+"Textbh"2+...+"Textbh (itoa l)"="(rtos tarea 2 2)"㎡"))
(command "_text" insPt0 TextHeight "" bb 0)
(princ )
)
(princ "\n未选择对象")
)
(setvar "cmdecho" 1)
(prin1)
) |
|