明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 2828|回复: 9

(求助)能否把下面程序的面积单位除以10六次方改为平方米,谢谢!

[复制链接]
发表于 2011-7-20 21:04:09 | 显示全部楼层 |阅读模式
(defun c:ttt(/ 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输入标注文字高度:")
TextIndex (getint "\n输入起始编号:")
)
  (ssget '((0 . "LWPOLYLINE")))
  (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 (itoa TextIndex) "号面积=" (rtos ObjArea) "平方米") (vlax-3d-point TextBasePoint) TextHeight)
     )
      (vla-put-alignment TextObj acAlignmentCenter)
      (vla-put-TextAlignmentPoint TextObj (vlax-3d-point TextBasePoint))
      (setq TextIndex (1+ TextIndex))      
      )
    )
  )
"觉得好,就打赏"
还没有人打赏,支持一下
发表于 2011-7-20 22:08:10 | 显示全部楼层
回复 cxs259 的帖子

;红色部份
(defun c:ttt(/ 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输入标注文字高度:")
TextIndex (getint "\n输入起始编号:")
)
  (ssget '((0 . "LWPOLYLINE")))
  (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 (itoa TextIndex) "号面积=" (rtos (/ ObjArea 1000000.0 )) "平方米") (vlax-3d-point TextBasePoint) TextHeight)
     )
      (vla-put-alignment TextObj acAlignmentCenter)
      (vla-put-TextAlignmentPoint TextObj (vlax-3d-point TextBasePoint))
      (setq TextIndex (1+ TextIndex))      
      )
    )
  )
发表于 2011-7-20 22:11:17 | 显示全部楼层
本帖最后由 gbhsu 于 2011-7-20 22:14 编辑

(defun c:ttt(/ 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输入标注文字高度:")
TextIndex (getint "\n输入起始编号:")
)
  (ssget '((0 . "LWPOLYLINE")))
  (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 (itoa TextIndex) "号面积=" (rtos (/ ObjArea 100000)) "平方米") (vlax-3d-point TextBasePoint) TextHeight)
     )
      (vla-put-alignment TextObj acAlignmentCenter)
      (vla-put-TextAlignmentPoint TextObj (vlax-3d-point TextBasePoint))
      (setq TextIndex (1+ TextIndex))      
      )
    )
  )
发表于 2011-7-20 22:12:36 | 显示全部楼层
本帖最后由 gbhsu 于 2011-7-20 22:16 编辑

程式不错,值得学习!
 楼主| 发表于 2011-8-3 09:22:39 | 显示全部楼层
首先谢谢祥子的解答!能否把下面程序的面积及周长的单位平方毫米/毫米,改成平方米/米,谢谢
面积与周长求和
(defun C:qqq (/ ss l i totalarea ename obj entarea)
  (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))
        ;;(vlax-dump-object obj T)
        (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 0) "平方豪米")
            text2 (strcat "总周长为: " (rtos totlength 2 0) "豪米")
      )
      (if (setq insertpt (getpoint "\n请输入文字插入点: "))
        (if (setq height (getdist "\n请输入文字高度:"))
          (setq insertp1 (vlax-3d-point insertpt)
                insertp2 (vlax-3d-point (polar insertpt (* 1.5 Pi) (* 1.5 height)))
                textobj1 (vla-addtext modelspace text1 insertp1 height)
                textobj2 (vla-addtext modelspace text2 insertp2 height)
          )
        )
      )
    )
  )
)
(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
)  
发表于 2012-11-1 10:34:44 | 显示全部楼层
好程序,顶!能否实现框选对象,自动标注?
发表于 2013-5-1 15:23:47 | 显示全部楼层
大将 发表于 2012-11-1 10:34
好程序,顶!能否实现框选对象,自动标注?

可以满足实现框选对象自动标注。
发表于 2013-5-1 17:23:41 | 显示全部楼层
这个函数不知道,待老大
发表于 2013-5-8 22:27:54 来自手机 | 显示全部楼层
手机复制代码不方便,留印明天下。谢谢
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-11-13 14:20 , Processed in 0.175717 second(s), 27 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表