乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
查看: 33|回复: 2

[求助]请问如何生成hatch的边界

[复制链接]

1

主题

1

帖子

1

银币

初来乍到

Rank: 1

铜币
5
发表于 2007-4-20 20:37:00 | 显示全部楼层 |阅读模式
图上有一个没有边界的hatch...我想为他生成边界
用appendloop函数行吗?  pHat->appendloop(1,objIds) 我用这样的语句时候..net报错
请教一下,该怎么为一个没有边界的hatch生成边界..
谢谢
回复

使用道具 举报

91

主题

389

帖子

12

银币

中流砥柱

Rank: 25

铜币
763
发表于 2007-4-26 08:07:00 | 显示全部楼层
  1. ;;; HATCHB.LSP ver 2.0
  2. ;;; Recreates hatch boundary by selecting a hatch
  3. ;;; Boundary is created in current layer/color/linetype in WCS
  4. ;;; By Jimmy Bergmark
  5. ;;; Copyright (C) 1997-2003 JTB World, All Rights Reserved
  6. ;;; Website: [url]www.jtbworld.com[/url]
  7. ;;; E-mail: [email]info@jtbworld.com[/email]
  8. ;;; 2000-02-12 - First release
  9. ;;; 2000-03-27 - Counterclockwise arc's and ellipse's fixed
  10. ;;;              Objects created joined to lwpolyline if possible
  11. ;;;              Error-handling, undo of command
  12. ;;;              Can handle PLINETYPE = 0,1,2
  13. ;;; 2000-03-30 - Integrating hatchb and hatchb14
  14. ;;;              Selection of many hatches
  15. ;;;              Splines supported if closed.
  16. ;;; 2001-04-02 - Fixed bug with entmake of line with no Z for r14
  17. ;;; 2001-07-31 - Removed an irritating semicolon to enable polylines to be created.
  18. ;;; 2001-10-04 - Changed mail and homepage so it's easy to find when new versions comes up.
  19. ;;; 2003-02-06 - Minor fix
  20. ;;; 2003-02-17 - Area returned if no islands is found since it's not consistant
  21. ;;; 2003-05-19 - Fix to take PEDITACCEPT variable used in AutoCAD 2004 into account
  22. ;;; Tested on AutoCAD r14, 2000, 2000i, 2002, 2004
  23. ;;; should be working on older versions too.
  24. (defun c:rebuild_hatch_border () (c:hb)) ; this line can be commented out if there is an existing command called hb
  25. (defun c:hb (/     es    blay  ed1   ed2   loops1      bptf  part
  26.              et    noe   plist ic    bul   nr    ang1  ang2  obj *ModelSpace* *PaperSpace*
  27.              space cw errexit undox olderr oldcmdecho ss1 lastent en1 en2 ss lwp
  28.              list->variantArray 3dPoint->2dPoint A2k ent i ss2
  29.              knot-list controlpoint-list kn cn pos xv bot area hst
  30.             )
  31. (setq A2k (>= (substr (getvar "ACADVER") 1 2) "15"))
  32. (if A2k
  33.    (progn
  34.      (defun list->variantArray (ptsList / arraySpace sArray)
  35.        (setq arraySpace
  36.           (vlax-make-safearray
  37.         vlax-vbdouble
  38.         (cons 0 (- (length ptsList) 1))
  39.           )
  40.        )
  41.        (setq sArray (vlax-safearray-fill arraySpace ptsList))
  42.        (vlax-make-variant sArray)
  43.      )
  44.      (defun areaOfObject (en / curve area)
  45.        (if en
  46.      (if A2k
  47.        (progn
  48.          (setq curve (vlax-ename->vla-object en))
  49.          (if
  50.            (vl-catch-all-error-p
  51.          (setq
  52.            area
  53.             (vl-catch-all-apply 'vlax-curve-getArea (list curve))
  54.          )
  55.            )
  56.         nil
  57.         area
  58.          )
  59.        )
  60.        (progn
  61.          (command "._area" "_O" en)
  62.          (getvar "area")
  63.        )
  64.      )
  65.        )
  66.      )
  67.    )
  68. )
  69. (if A2k
  70.   (defun 3dPoint->2dPoint (3dpt)
  71.     (list (float (car 3dpt)) (float (cadr 3dpt)))
  72.   )
  73. )
  74.   (defun errexit (s)
  75.     (princ "\nError:  ")
  76.     (princ s)
  77.     (restore)
  78.   )
  79.   (defun undox ()
  80.     (command "._ucs" "_p")
  81.     (command "._undo" "_E")
  82.     (setvar "cmdecho" oldcmdecho)
  83.     (setq *error* olderr)
  84.     (princ)
  85.   )
  86.   (setq olderr  *error*
  87.         restore undox
  88.         *error* errexit
  89.   )
  90.   (setq oldcmdecho (getvar "cmdecho"))
  91.   (setvar "cmdecho" 0)
  92.   (command "._UNDO" "_BE")
  93.   (if A2k (progn
  94.     (vl-load-com)
  95.     (setq *ModelSpace* (vla-get-ModelSpace
  96.                          (vla-get-ActiveDocument (vlax-get-acad-object))
  97.                        )
  98.           *PaperSpace* (vla-get-PaperSpace
  99.                          (vla-get-ActiveDocument (vlax-get-acad-object))
  100.                        )
  101.     ))
  102.   ) ; For testing purpose
  103. ; (setq A2k nil)
  104.    
  105.   (if (/= (setq ss2 (ssget '((0 . "HATCH")))) nil)
  106.    (progn
  107.     (setq i 0)
  108.     (setq area 0)
  109.     (setq bMoreLoops nil)
  110.     (while (setq ent (ssname ss2 i))
  111.       (setq ed1 (entget ent))
  112.       (if (not (equal (assoc 210 ed1) '(210 0.0 0.0 1.0))) (princ "\nHatch not in WCS!"))
  113.       (setq xv (cdr (assoc 210 ed1)))
  114.       (command "._ucs" "_w")
  115.       (setq loops1 (cdr (assoc 91 ed1))) ; number of boundary paths (loops)
  116.       (if (and A2k (= (strcase (cdr (assoc 410 ed1))) "MODEL"))
  117.         (setq space *ModelSpace*)
  118.         (setq space *PaperSpace*)
  119.       )
  120.       (repeat loops1
  121.         (setq ed1 (member (assoc 92 ed1) ed1))
  122.         (setq bptf (cdr (car ed1))) ; boundary path type flag
  123.         (setq ic (cdr (assoc 73 ed1))) ; is closed
  124.         (setq noe (cdr (assoc 93 ed1))) ; number of edges
  125.     (setq bot (cdr (assoc 92 ed1))) ; boundary type
  126.     (setq hst (cdr (assoc 75 ed1))) ; hatch style
  127.         (setq ed1 (member (assoc 72 ed1) ed1))
  128.         (setq bul (cdr (car ed1))) ; bulge
  129.         (setq plist nil)
  130.         (setq blist nil)
  131.         (cond
  132.           ((> (boole 1 bptf 2) 0) ; polyline
  133.            (repeat noe
  134.              (setq ed1 (member (assoc 10 (cdr ed1)) ed1))
  135.              (setq plist (append plist (list (cdr (assoc 10 ed1)))))
  136.              (setq blist (append blist
  137.                                  (if (> bul 0)
  138.                                    (list (cdr (assoc 42 ed1)))
  139.                                    nil
  140.                                  )
  141.                          )
  142.              )
  143.            )
  144.            (if A2k (progn
  145.              (setq polypoints
  146.                     (apply 'append
  147.                            (mapcar '3dPoint->2dPoint plist)
  148.                     )
  149.              )
  150.              (setq VLADataPts (list->variantArray polypoints))
  151.              (setq obj (vla-addLightweightPolyline space VLADataPts))
  152.              (setq nr 0)
  153.              (repeat (length blist)
  154.                (if (/= (nth nr blist) 0)
  155.                  (vla-setBulge obj nr (nth nr blist))
  156.                )
  157.                (setq nr (1+ nr))
  158.              )
  159.              (if (= ic 1)
  160.                (vla-put-closed obj T)
  161.              )
  162.             )
  163.             (progn
  164.               (if (= ic 1)
  165.                 (entmake '((0 . "POLYLINE") (66 . 1) (70 . 1)))
  166.                 (entmake '((0 . "POLYLINE") (66 . 1)))
  167.               )
  168.               (setq nr 0)
  169.               (repeat (length plist)
  170.                 (if (= bul 0)
  171.                   (entmake (list (cons 0 "VERTEX")
  172.                                  (cons 10 (nth nr plist))
  173.                            )
  174.                   )
  175.                   (entmake (list (cons 0 "VERTEX")
  176.                                  (cons 10 (nth nr plist))
  177.                                  (cons 42 (nth nr blist))
  178.                            )
  179.                   )
  180.                 )
  181.                 (setq nr (1+ nr))
  182.               )
  183.               (entmake '((0 . "SEQEND")))
  184.             )
  185.            )
  186.           )
  187.           (t ; not polyline
  188.            (setq lastent (entlast))
  189.            (setq lwp T)
  190.            (repeat noe
  191.              (setq et (cdr (assoc 72 ed1)))
  192.              (cond
  193.                ((= et 1) ; line
  194.                 (setq ed1 (member (assoc 10 (cdr ed1)) ed1))
  195.                 (if A2k
  196.                   (vla-AddLine
  197.                     space
  198.                     (vlax-3d-point (cdr (assoc 10 ed1)))
  199.                     (vlax-3d-point (cdr (assoc 11 ed1)))
  200.                   )
  201.                   (entmake
  202.                     (list
  203.                       (cons 0 "LINE")
  204.                       (list 10 (cadr (assoc 10 ed1)) (caddr (assoc 10 ed1)) 0)
  205.                       (list 11 (cadr (assoc 11 ed1)) (caddr (assoc 11 ed1)) 0)
  206.             ;  (cons 210 xv)
  207.                     )
  208.                   )
  209.                 )
  210.                 (setq ed1 (cddr ed1))
  211.                )
  212.                ((= et 2) ; circular arc
  213.                  (setq ed1 (member (assoc 10 (cdr ed1)) ed1))
  214.                  (setq ang1 (cdr (assoc 50 ed1)))
  215.                  (setq ang2 (cdr (assoc 51 ed1)))
  216.                  (setq cw (cdr (assoc 73 ed1)))
  217.                  (if (equal ang2 6.28319 0.00001)
  218.                    (progn
  219.                      (if A2k
  220.                        (vla-AddCircle
  221.                          space
  222.                          (vlax-3d-point (cdr (assoc 10 ed1)))
  223.                          (cdr (assoc 40 ed1))
  224.                        )
  225.                        (entmake (list (cons 0 "CIRCLE")
  226.                                       (assoc 10 ed1)
  227.                                       (assoc 40 ed1)
  228.                                 )
  229.                        )
  230.                      )
  231.                      (setq lwp nil)
  232.                    )
  233.                    (if A2k
  234.                      (vla-AddArc
  235.                        space
  236.                        (vlax-3d-point (cdr (assoc 10 ed1)))
  237.                        (cdr (assoc 40 ed1))
  238.                        (if (= cw 0)
  239.                          (- 0 ang2)
  240.                          ang1
  241.                        )
  242.                        (if (= cw 0)
  243.                          (- 0 ang1)
  244.                          ang2
  245.                        )
  246.                      )
  247.                      (entmake (list (cons 0 "ARC")
  248.                                     (assoc 10 ed1)
  249.                                     (assoc 40 ed1)
  250.                                     (cons 50
  251.                                           (if (= cw 0)
  252.                                             (- 0 ang2)
  253.                                             ang1
  254.                                           )
  255.                                     )
  256.                                     (cons 51
  257.                                           (if (= cw 0)
  258.                                             (- 0 ang1)
  259.                                             ang2
  260.                                           )
  261.                                     )
  262.                               )
  263.                      )
  264.                    )
  265.                  )
  266.                  (setq ed1 (cddddr ed1))
  267.                )
  268.                ((= et 3) ; elliptic arc
  269.                 (setq ed1 (member (assoc 10 (cdr ed1)) ed1))
  270.                 (setq ang1 (cdr (assoc 50 ed1)))
  271.                 (setq ang2 (cdr (assoc 51 ed1)))
  272.                 (setq cw (cdr (assoc 73 ed1)))
  273.                 (if A2k (progn
  274.                   (setq obj (vla-AddEllipse
  275.                               space
  276.                               (vlax-3d-point (cdr (assoc 10 ed1)))
  277.                               (vlax-3d-point (cdr (assoc 11 ed1)))
  278.                               (cdr (assoc 40 ed1))
  279.                             )
  280.                   )
  281.                   (vla-put-startangle obj (if (= cw 0) (- 0 ang2) ang1))
  282.                   (vla-put-endangle obj (if (= cw 0) (- 0 ang1) ang2))
  283.                  )
  284.                  (princ "\nElliptic arc not supported!")
  285.                 )
  286.                 (setq lwp nil)
  287.                )
  288.                ((= et 4) ; spline
  289.                 (setq ed1 (member (assoc 94 (cdr ed1)) ed1))
  290.                 (setq knot-list nil)
  291.                 (setq controlpoint-list nil)
  292.         (setq kn (cdr (assoc 95 ed1)))
  293.                 (setq cn (cdr (assoc 96 ed1)))
  294.                 (setq pos (vl-position (assoc 40 ed1) ed1))
  295.                 (repeat kn
  296.                   (setq knot-list (cons (cons 40 (cdr (nth pos ed1))) knot-list))
  297.                   (setq pos (1+ pos))
  298.                 )
  299.                 (setq pos (vl-position (assoc 10 ed1) ed1))
  300.                 (repeat cn
  301.                   (setq controlpoint-list (cons (cons 10 (cdr (nth pos ed1))) controlpoint-list))
  302.                   (setq pos (1+ pos))
  303.                 )
  304.                 (setq knot-list (reverse knot-list))
  305.                 (setq controlpoint-list (reverse controlpoint-list))
  306.                 (entmake (append
  307.                        (list '(0 . "SPLINE"))
  308.                                (list (cons 100 "AcDbEntity"))
  309.                                (list (cons 100 "AcDbSpline"))
  310.                                (list (cons 70 (+ 1 8 (* 2 (cdr (assoc 74 ed1))) (* 4 (cdr (assoc 73 ed1))))))
  311.                                (list (cons 71 (cdr (assoc 94 ed1))))
  312.                                (list (cons 72 kn))
  313.                                (list (cons 73 cn))
  314.                                knot-list
  315.                                controlpoint-list
  316.                       )
  317.                 )
  318.         (setq ed1 (member (assoc 10 ed1) ed1))
  319.                 (setq lwp nil)
  320.                )
  321.              ) ; end cond
  322.            ) ; end repeat noe
  323.            (if lwp (progn
  324.              (setq en1 (entnext lastent))
  325.              (setq ss (ssadd))
  326.              (ssadd en1 ss)
  327.              (while (setq en2 (entnext en1))
  328.                (ssadd en2 ss)
  329.                (setq en1 en2)
  330.              )
  331.          (if (= (getvar "peditaccept") 1)
  332.                (command "_.pedit" (entlast) "_J" ss "" "")
  333.            (command "_.pedit" (entlast) "_Y" "_J" ss "" "")
  334.          )
  335.           ))
  336.           ) ; end t
  337.         ) ; end cond
  338. ;    Tries to get the area on islands but it's not clear how to know if an island is filled or not
  339. ;    and if it should be substracted or added to the total area.
  340. ;    (if (or (= bot 0) (= (boole 1 bot 1) 1)) (setq area (+ area (areaOfObject (entlast)))))
  341. ;    (if (and (/= hst 1) (/= bot 0) (= (boole 1 bot 1) 0)) (setq area (- area (areaOfObject (entlast)))))
  342. ;    (princ "\n") (princ bot) (princ "\n") (princ hst) (princ "\n")
  343. ;    (princ (areaOfObject (entlast)))
  344.       ) ; end repeat loops1
  345.       (if (= loops1 1) (setq area (+ area (areaOfObject (entlast)))) (setq bMoreLoops T))
  346.       (setq i (1+ i))
  347.     )
  348.    )
  349.   )
  350.   (if (and area (not bMoreLoops)) (progn
  351.     (princ "\nTotal Area = ")
  352.     (princ area)
  353.   ))
  354.   (restore)
  355.   (princ)
  356. )
输入HB即可!
回复

使用道具 举报

004

17

主题

110

帖子

8

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
178
发表于 2012-10-30 14:10:00 | 显示全部楼层
看着好复杂啊。
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-2-5 09:55 , Processed in 0.192122 second(s), 58 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表