找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 1080|回复: 9

[编程申请]:求一lsp程序:选中填充图案后自动计算填充面积,并打印至屏幕

[复制链接]
发表于 2006-2-16 19:56:37 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

×
在园林设计中经常要计算填充区域的面积,希望编一程序能在选中图案后自动计算填充面积,并打印至屏幕。*-*4
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
发表于 2006-2-17 15:24:57 | 显示全部楼层
每天都要在这个上面耗费几个小时,太浪费时间了!
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

发表于 2006-2-17 19:39:56 | 显示全部楼层
建筑也和需要这样的工具!现在面积要交电子文件,确实黑废时间!
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

发表于 2006-2-18 22:30:05 | 显示全部楼层
这个好像不需要编程吧,cad2006本身的字段功能就可以解决的。
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

发表于 2006-3-19 22:36:16 | 显示全部楼层
因lp的需要,改了一下别人的程序,看看能用不?!

  1. ;;; HATCHB.LSP ver 2.2
  2. ;;; Recreates hatch boundary by selecting a hatch
  3. ;;; Boundary is created in current layer/color/linetype in WCS
  4. ;;; Known problem with some elipses and splines
  5. ;;; By Jimmy Bergmark
  6. ;;; Copyright (C) 1997-2006 JTB World, All Rights Reserved
  7. ;;; Website: [url]www.jtbworld.com[/url]
  8. ;;; E-mail: [email]info@jtbworld.com[/email]
  9. ;;; 2000-02-12 - First release
  10. ;;; 2000-03-27 - Counterclockwise arc's and ellipse's fixed
  11. ;;;              Objects created joined to lwpolyline if possible
  12. ;;;              Error-handling, undo of command
  13. ;;;              Can handle PLINETYPE = 0,1,2
  14. ;;; 2000-03-30 - Integrating hatchb and hatchb14
  15. ;;;              Selection of many hatches
  16. ;;;              Splines supported if closed.
  17. ;;; 2001-04-02 - Fixed bug with entmake of line with no Z for r14
  18. ;;; 2001-07-31 - Removed an irritating semicolon to enable polylines to be created.
  19. ;;; 2001-10-04 - Changed mail and homepage so it's easy to find when new versions comes up.
  20. ;;; 2003-02-06 - Minor fix
  21. ;;; 2003-02-17 - Area returned if no islands is found since it's not consistant
  22. ;;; 2003-05-19 - Fix to take PEDITACCEPT variable used in AutoCAD 2004 into account
  23. ;;; 2004-11-05 - Minor bugs fixed
  24. ;;; 2006-03-18 - Nothing changed from 2.1 other that it's been confirmed to work with AutoCAD 2007
  25. ;;; Tested on AutoCAD r14, 2000, 2000i, 2002, 2004, 2005, 2006, 2007
  26. ;;; should be working on older versions too.

  27. (defun c:hb () (c:hatchb))                ; this line can be commented out if there is an existing command called hb
  28. (defun c:hatchb        (/           es             blay      ed1         ed2
  29.                  loops1           bptf             part      et         noe
  30.                  plist           ic             bul       nr         ang1
  31.                  ang2           obj             *ModelSpace*         *PaperSpace*
  32.                  space           cw             errexit   undox         olderr
  33.                  oldcmdecho             ss1       lastent         en1
  34.                  en2           ss             lwp       list->variantArray
  35.                  3dPoint->2dPoint    A2k       ent         i
  36.                  ss2           knot-list controlpoint-list         kn
  37.                  cn           pos             xv               bot         area
  38.                  hst
  39.                 )
  40.   (defun ax:Centroid (poly / pl ms va reg cen)
  41.     (setq pl (vlax-ename->vla-object poly)
  42.           ms (vla-get-modelspace
  43.                (vla-get-activedocument (vlax-get-acad-object))
  44.              )
  45.           va (vlax-make-safearray vlax-vbObject '(0 . 0))
  46.     )
  47.     (vlax-safearray-put-element va 0 pl)
  48.     (setq reg (car (vlax-safearray->list
  49.                      (vlax-variant-value (vla-addregion ms va))
  50.                    )
  51.               )
  52.           cen (vla-get-centroid reg)
  53.     )
  54.     (vla-delete reg)
  55.     (vlax-safearray->list (vlax-variant-value cen))
  56.   )
  57.   (defun tt (aa /)
  58.     (setq pt (ax:Centroid (entlast)))
  59.     (entdel (entlast))
  60.     (entmake (list '(0 . "TEXT")
  61.                    '(8 . "RD-面积标注")
  62.                    (cons 10 pt)
  63.                    '(40 . 20)                   ;40.后的数字为文字高度
  64.                    '(41 . 0.7)
  65.                    (cons 1 (rtos (/ aa 10000) 2 4))
  66.                    '(71 . 0)
  67.                    '(72 . 4)
  68.                    (cons 11 pt)
  69.                    '(73 . 0)
  70.              )

  71.     )
  72.   )
  73.   (setq A2k (>= (substr (getvar "ACADVER") 1 2) "15"))
  74.   (if A2k
  75.     (progn
  76.       (defun list->variantArray        (ptsList / arraySpace sArray)
  77.         (setq arraySpace
  78.                (vlax-make-safearray
  79.                  vlax-vbdouble
  80.                  (cons 0 (- (length ptsList) 1))
  81.                )
  82.         )
  83.         (setq sArray (vlax-safearray-fill arraySpace ptsList))
  84.         (vlax-make-variant sArray)
  85.       )
  86.       (defun areaOfObject (en / curve area)
  87.         (if en
  88.           (if A2k
  89.             (progn
  90.               (setq curve (vlax-ename->vla-object en))
  91.               (if
  92.                 (vl-catch-all-error-p
  93.                   (setq
  94.                     area
  95.                      (vl-catch-all-apply 'vlax-curve-getArea (list curve))
  96.                   )
  97.                 )
  98.                  nil
  99.                  area
  100.               )
  101.             )
  102.             (progn
  103.               (command "._area" "_O" en)
  104.               (getvar "area")
  105.             )
  106.           )
  107.         )
  108.       )
  109.     )
  110.   )
  111.   (if A2k
  112.     (defun 3dPoint->2dPoint (3dpt)
  113.       (list (float (car 3dpt)) (float (cadr 3dpt)))
  114.     )
  115.   )

  116.   (defun errexit (s)
  117.     (princ "\nError:  ")
  118.     (princ s)
  119.     (restore)
  120.   )

  121.   (defun undox ()
  122.     (command "._ucs" "_p")
  123.     (command "._undo" "_E")
  124.     (setvar "cmdecho" oldcmdecho)
  125.     (setq *error* olderr)
  126.     (princ)
  127.   )

  128.   (setq        olderr        *error*
  129.         restore        undox
  130.         *error*        errexit
  131.   )
  132.   (setq oldcmdecho (getvar "cmdecho"))
  133.   (setvar "cmdecho" 0)
  134.   (command "._UNDO" "_BE")
  135.   (if A2k
  136.     (progn
  137.       (vl-load-com)
  138.       (setq *ModelSpace* (vla-get-ModelSpace
  139.                            (vla-get-ActiveDocument (vlax-get-acad-object))
  140.                          )
  141.             *PaperSpace* (vla-get-PaperSpace
  142.                            (vla-get-ActiveDocument (vlax-get-acad-object))
  143.                          )
  144.       )
  145.     )
  146.   )


  147.                                         ; For testing purpose
  148.                                         ; (setq A2k nil)

  149.   (if (/= (setq ss2 (ssget '((0 . "HATCH")))) nil)
  150.     (progn
  151.       (setq i 0)
  152.       (setq area 0)
  153.       (setq bMoreLoops nil)
  154.       (while (setq ent (ssname ss2 i))
  155.         (setq ed1 (entget ent))
  156.         (if (not (equal (assoc 210 ed1) '(210 0.0 0.0 1.0)))
  157.           (princ "\nHatch not in WCS!")
  158.         )
  159.         (setq xv (cdr (assoc 210 ed1)))
  160.         (command "._ucs" "_w")
  161.         (setq loops1 (cdr (assoc 91 ed1)))
  162.                                         ; number of boundary paths (loops)
  163.         (if (and A2k (= (strcase (cdr (assoc 410 ed1))) "MODEL"))
  164.           (setq space *ModelSpace*)
  165.           (setq space *PaperSpace*)
  166.         )
  167.         (repeat        loops1
  168.           (setq ed1 (member (assoc 92 ed1) ed1))
  169.           (setq bptf (cdr (car ed1)))        ; boundary path type flag
  170.           (setq ic (cdr (assoc 73 ed1))) ; is closed
  171.           (setq noe (cdr (assoc 93 ed1))) ; number of edges
  172.           (setq bot (cdr (assoc 92 ed1))) ; boundary type
  173.           (setq hst (cdr (assoc 75 ed1))) ; hatch style
  174.           (setq ed1 (member (assoc 72 ed1) ed1))
  175.           (setq bul (cdr (car ed1)))        ; bulge
  176.           (setq plist nil)
  177.           (setq blist nil)
  178.           (cond
  179.             ((> (boole 1 bptf 2) 0)        ; polyline
  180.              (repeat noe
  181.                (setq ed1 (member (assoc 10 (cdr ed1)) ed1))
  182.                (setq plist (append plist (list (cdr (assoc 10 ed1)))))
  183.                (setq blist (append blist
  184.                                    (if (> bul 0)
  185.                                      (list (cdr (assoc 42 ed1)))
  186.                                      nil
  187.                                    )
  188.                            )
  189.                )
  190.              )
  191.              (if A2k
  192.                (progn
  193.                  (setq polypoints
  194.                         (apply 'append
  195.                                (mapcar '3dPoint->2dPoint plist)
  196.                         )
  197.                  )
  198.                  (setq VLADataPts (list->variantArray polypoints))
  199.                  (setq
  200.                    obj (vla-addLightweightPolyline space VLADataPts)
  201.                  )
  202.                  (setq nr 0)
  203.                  (repeat (length blist)
  204.                    (if (/= (nth nr blist) 0)
  205.                      (vla-setBulge obj nr (nth nr blist))
  206.                    )
  207.                    (setq nr (1+ nr))
  208.                  )
  209.                  (if (= ic 1)
  210.                    (vla-put-closed obj T)
  211.                  )
  212.                )
  213.                (progn
  214.                  (if (= ic 1)
  215.                    (entmake '((0 . "POLYLINE") (66 . 1) (70 . 1)))
  216.                    (entmake '((0 . "POLYLINE") (66 . 1)))
  217.                  )
  218.                  (setq nr 0)
  219.                  (repeat (length plist)
  220.                    (if (= bul 0)
  221.                      (entmake (list (cons 0 "VERTEX")
  222.                                     (cons 10 (nth nr plist))
  223.                               )
  224.                      )
  225.                      (entmake (list (cons 0 "VERTEX")
  226.                                     (cons 10 (nth nr plist))
  227.                                     (cons 42 (nth nr blist))
  228.                               )
  229.                      )
  230.                    )
  231.                    (setq nr (1+ nr))
  232.                  )
  233.                  (entmake '((0 . "SEQEND")))
  234.                )
  235.              )
  236.             )
  237.             (t                                ; not polyline
  238.              (setq lastent (entlast))
  239.              (setq lwp T)
  240.              (repeat noe
  241.                (setq et (cdr (assoc 72 ed1)))
  242.                (cond
  243.                  ((= et 1)                ; line
  244.                   (setq ed1 (member (assoc 10 (cdr ed1)) ed1))
  245.                   (if A2k
  246.                     (vla-AddLine
  247.                       space
  248.                       (vlax-3d-point (cdr (assoc 10 ed1)))
  249.                       (vlax-3d-point (cdr (assoc 11 ed1)))
  250.                     )
  251.                     (entmake
  252.                       (list
  253.                         (cons 0 "LINE")
  254.                         (list 10
  255.                               (cadr (assoc 10 ed1))
  256.                               (caddr (assoc 10 ed1))
  257.                               0
  258.                         )
  259.                         (list 11
  260.                               (cadr (assoc 11 ed1))
  261.                               (caddr (assoc 11 ed1))
  262.                               0
  263.                         )
  264.                                         ;  (cons 210 xv)
  265.                       )
  266.                     )
  267.                   )
  268.                   (setq ed1 (cddr ed1))
  269.                  )
  270.                  ((= et 2)                ; circular arc
  271.                   (setq ed1 (member (assoc 10 (cdr ed1)) ed1))
  272.                   (setq ang1 (cdr (assoc 50 ed1)))
  273.                   (setq ang2 (cdr (assoc 51 ed1)))
  274.                   (setq cw (cdr (assoc 73 ed1)))
  275.                   (if (and (equal ang1 0 0.00001)
  276.                            (equal ang2 6.28319 0.00001)
  277.                       )
  278.                     (progn
  279.                       (if A2k
  280.                         (vla-AddCircle
  281.                           space
  282.                           (vlax-3d-point (cdr (assoc 10 ed1)))
  283.                           (cdr (assoc 40 ed1))
  284.                         )
  285.                         (entmake (list (cons 0 "CIRCLE")
  286.                                        (assoc 10 ed1)
  287.                                        (assoc 40 ed1)
  288.                                  )
  289.                         )
  290.                       )
  291.                       (setq lwp nil)
  292.                     )
  293.                     (if        A2k
  294.                       (vla-AddArc
  295.                         space
  296.                         (vlax-3d-point (cdr (assoc 10 ed1)))
  297.                         (cdr (assoc 40 ed1))
  298.                         (if (= cw 0)
  299.                           (- 0 ang2)
  300.                           ang1
  301.                         )
  302.                         (if (= cw 0)
  303.                           (- 0 ang1)
  304.                           ang2
  305.                         )
  306.                       )
  307.                       (entmake (list (cons 0 "ARC")
  308.                                      (assoc 10 ed1)
  309.                                      (assoc 40 ed1)
  310.                                      (cons 50
  311.                                            (if (= cw 0)
  312.                                              (- 0 ang2)
  313.                                              ang1
  314.                                            )
  315.                                      )
  316.                                      (cons 51
  317.                                            (if (= cw 0)
  318.                                              (- 0 ang1)
  319.                                              ang2
  320.                                            )
  321.                                      )
  322.                                )
  323.                       )
  324.                     )
  325.                   )
  326.                   (setq ed1 (cddddr ed1))
  327.                  )
  328.                  ((= et 3)                ; elliptic arc
  329.                   (setq ed1 (member (assoc 10 (cdr ed1)) ed1))
  330.                   (setq ang1 (cdr (assoc 50 ed1)))
  331.                   (setq ang2 (cdr (assoc 51 ed1)))
  332.                   (setq cw (cdr (assoc 73 ed1)))
  333.                   (if A2k
  334.                     (progn
  335.                       (setq obj        (vla-AddEllipse
  336.                                   space
  337.                                   (vlax-3d-point (cdr (assoc 10 ed1)))
  338.                                   (vlax-3d-point (cdr (assoc 11 ed1)))
  339.                                   (cdr (assoc 40 ed1))
  340.                                 )
  341.                       )
  342.                       (vla-put-startangle
  343.                         obj
  344.                         (if (= cw 0)
  345.                           (- 0 ang2)
  346.                           ang1
  347.                         )
  348.                       )
  349.                       (vla-put-endangle
  350.                         obj
  351.                         (if (= cw 0)
  352.                           (- 0 ang1)
  353.                           ang2
  354.                         )
  355.                       )
  356.                     )
  357.                     (princ "\nElliptic arc not supported!")
  358.                   )
  359.                   (setq lwp nil)
  360.                  )
  361.                  ((= et 4)                ; spline
  362.                   (setq ed1 (member (assoc 94 (cdr ed1)) ed1))
  363.                   (setq knot-list nil)
  364.                   (setq controlpoint-list nil)
  365.                   (setq kn (cdr (assoc 95 ed1)))
  366.                   (setq cn (cdr (assoc 96 ed1)))
  367.                   (setq pos (vl-position (assoc 40 ed1) ed1))
  368.                   (repeat kn
  369.                     (setq
  370.                       knot-list        (cons (cons 40 (cdr (nth pos ed1)))
  371.                                       knot-list
  372.                                 )
  373.                     )
  374.                     (setq pos (1+ pos))
  375.                   )
  376.                   (setq pos (vl-position (assoc 10 ed1) ed1))
  377.                   (repeat cn
  378.                     (setq controlpoint-list
  379.                            (cons
  380.                              (cons 10 (cdr (nth pos ed1)))
  381.                              controlpoint-list
  382.                            )
  383.                     )
  384.                     (setq pos (1+ pos))
  385.                   )
  386.                   (setq knot-list (reverse knot-list))
  387.                   (setq controlpoint-list (reverse controlpoint-list))
  388.                   (entmake (append
  389.                              (list '(0 . "SPLINE"))
  390.                              (list (cons 100 "AcDbEntity"))
  391.                              (list (cons 100 "AcDbSpline"))
  392.                              (list (cons 70
  393.                                          (+ 1
  394.                                             8
  395.                                             (* 2 (cdr (assoc 74 ed1)))
  396.                                             (* 4 (cdr (assoc 73 ed1)))
  397.                                          )
  398.                                    )
  399.                              )
  400.                              (list (cons 71 (cdr (assoc 94 ed1))))
  401.                              (list (cons 72 kn))
  402.                              (list (cons 73 cn))
  403.                              knot-list
  404.                              controlpoint-list
  405.                            )
  406.                   )
  407.                   (setq ed1 (member (assoc 10 ed1) ed1))
  408.                   (setq lwp nil)
  409.                  )
  410.                )                        ; end cond
  411.              )                                ; end repeat noe
  412.              (if lwp
  413.                (progn
  414.                  (setq en1 (entnext lastent))
  415.                  (setq ss (ssadd))
  416.                  (ssadd en1 ss)
  417.                  (while        (setq en2 (entnext en1))
  418.                    (ssadd en2 ss)
  419.                    (setq en1 en2)
  420.                  )
  421.                  (if (= (getvar "peditaccept") 1)
  422.                    (command "_.pedit" (entlast) "_J" ss "" "")
  423.                    (command "_.pedit" (entlast) "_Y" "_J" ss "" "")
  424.                  )
  425.                )
  426.              )

  427.             )                                ; end t
  428.           )                                ; end cond
  429.                                         ;        Tries to get the area on islands but it's not clear how to know if an island is filled or not
  430.                                         ;        and if it should be substracted or added to the total area.
  431.                                         ;        (if (or (= bot 0) (= (boole 1 bot 1) 1)) (setq area (+ area (areaOfObject (entlast)))))
  432.                                         ;        (if (and (/= hst 1) (/= bot 0) (= (boole 1 bot 1) 0)) (setq area (- area (areaOfObject (entlast)))))
  433.                                         ;        (princ "\n") (princ bot) (princ "\n") (princ hst) (princ "\n")
  434.                                         ;        (princ (areaOfObject (entlast)))
  435.         )                                ; end repeat loops1
  436.         (if (= loops1 1)
  437.           (progn (setq aa   (areaOfObject (entlast))
  438.                        area (+ area aa)
  439.                  )
  440.                  (tt aa)
  441.           )
  442.           (setq bMoreLoops T)
  443.         )
  444.         (setq i (1+ i))
  445.       )
  446.     )
  447.   )
  448.   (if (and area (not bMoreLoops))
  449.     (progn
  450.       (princ "\nTotal Area = ")
  451.       (princ area)
  452.     )
  453.   )

  454.   (restore)
  455.   (princ)
  456. )

论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

已领礼包: 5个

财富等级: 恭喜发财

发表于 2015-10-10 10:07:40 | 显示全部楼层
忠心感谢david96007的lisp程序!他粘贴出来的代码,复制到文本文件中有很多问号,我整理了下。他的程序好像面积默认除以10000,单位是公倾,修改了下不除以10000,单位为平方米;精度修改为整数。
  (cons 1 (rtos (/ aa 1000) 2 4))
改为  (cons 1 (rtos (/ aa 1) 2 0))

hatchb2.2.rar

3.41 KB, 下载次数: 58, 下载积分: D豆 -1 , 活跃度 1

论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

发表于 2015-10-25 00:56:02 | 显示全部楼层
提示: 作者被禁止或删除 内容自动屏蔽
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

已领礼包: 2个

财富等级: 恭喜发财

发表于 2021-10-13 08:40:12 | 显示全部楼层
来学习咯啊啊
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

发表于 2021-11-19 10:55:38 | 显示全部楼层

来学习咯啊啊
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|申请友链|Archiver|手机版|小黑屋|辽公网安备|晓东CAD家园 ( 辽ICP备15016793号 )

GMT+8, 2024-5-29 10:02 , Processed in 0.503881 second(s), 51 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

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