明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 2761|回复: 2

Lee Mac大侠的新程序,麻烦高手给加个注释,不胜感谢!!!

[复制链接]
发表于 2012-3-21 21:25:37 | 显示全部楼层 |阅读模式
本帖最后由 soly2006 于 2012-3-21 21:27 编辑


  1. ;;-------------------=={ Areas 2 Field }==--------------------;;
  2. ;;                                                            ;;
  3. ;;  Creates an MText Field referencing the sum of the areas   ;;
  4. ;;  of selected objects.                                      ;;
  5. ;;------------------------------------------------------------;;
  6. ;;  Author: Lee Mac, Copyright ?2012 - www.lee-mac.com       ;;
  7. ;;------------------------------------------------------------;;
  8. ;;  Version 1.1    -    14-03-2012                            ;;
  9. ;;------------------------------------------------------------;;

  10. (defun c:A2F (/                *error*          _startundo              _endundo
  11.               _objectid        acdoc          acsel            count     field
  12.               format        pt
  13.              )

  14.   (setq format "%lu6%qf1")
  15.   ;; Field Formatting

  16.   (defun *error* (msg)
  17.     (if        acdoc
  18.       (_endundo acdoc)
  19.     )
  20.     (or        (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*")
  21.         (princ (strcat "\n** Error: " msg " **"))
  22.     )
  23.     (princ)
  24.   )

  25.   (defun _startundo (doc)
  26.     (_endundo doc)
  27.     (vla-StartUndoMark doc)
  28.   )

  29.   (defun _endundo (doc)
  30.     (while (= 8 (logand 8 (getvar 'UNDOCTL)))
  31.       (vla-EndUndoMark doc)
  32.     )
  33.   )

  34.   (setq acdoc (vla-get-activedocument (vlax-get-acad-object)))
  35.   (setq        _objectid
  36.          (eval
  37.            (list 'lambda
  38.                  '(obj)
  39.                  (if
  40.                    (and
  41.                      (vl-string-search "64" (getenv "PROCESSOR_ARCHITECTURE"))
  42.                      (vlax-method-applicable-p
  43.                        (vla-get-utility acdoc)
  44.                        'getobjectidstring
  45.                      )
  46.                    )
  47.                     (list 'vla-getobjectidstring
  48.                           (vla-get-utility acdoc)
  49.                           'obj
  50.                           ':vlax-
  51.                           false
  52.                     )
  53.                     '(itoa (vla-get-objectid obj))
  54.                  )
  55.            )
  56.          )
  57.   )

  58.   (if
  59.     (and
  60.       (ssget
  61.         '((0 . "ARC,CIRCLE,ELLIPSE,HATCH,*POLYLINE,REGION,SPLINE"))
  62.       )
  63.       (setq pt (getpoint "\nPick Point for Field: "))
  64.     )
  65.      (progn
  66.        (setq acsel (vla-get-activeselectionset acdoc)
  67.              count (vla-get-count acsel)
  68.              field (if (< 1 count)
  69.                      "%<\\AcExpr "
  70.                      ""
  71.                    )
  72.        )
  73.        (_startundo acdoc)
  74.        (vlax-for obj acsel
  75.          (setq field (strcat field
  76.                              "%<\\AcObjProp Object(%<\\_ObjId "
  77.                              (_objectid
  78.                                obj
  79.                              )
  80.                              ">%).Area>% + "
  81.                      )
  82.          )
  83.        )
  84.        (vla-delete acsel)
  85.        (vla-addmtext
  86.          (vlax-get-property
  87.            acdoc
  88.            (if (= 1 (getvar 'CVPORT))
  89.              'paperspace
  90.              'modelspace
  91.            )
  92.          )
  93.          (vlax-3D-point (trans pt 1 0))
  94.          0.0
  95.          (strcat (substr field
  96.                          1
  97.                          (- (strlen field)
  98.                             (if        (< 1 count)
  99.                               3
  100.                               5
  101.                             )
  102.                          )
  103.                  )
  104.                  " \\f
  105. ""                 format
  106.                  "">%"
  107.          )
  108.        )
  109.        (_endundo acdoc)
  110.      )
  111.   )
  112.   (princ)
  113. )
  114. (vl-load-com)
  115. (princ)

点评

这个没什么可注释的,首先你要搞懂域的概念,然后再看这个程序就简单了!  发表于 2012-3-21 22:02
"觉得好,就打赏"
还没有人打赏,支持一下
发表于 2012-3-29 16:53:24 | 显示全部楼层
好象有问题    生成不了文字
发表于 2012-3-29 21:19:50 | 显示全部楼层
一开始看演示,也以为是反应器做的,看了代码,是用命令field里的对象属性来实现的。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-9-25 04:47 , Processed in 0.166778 second(s), 30 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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