乐筑天下

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

[综合讨论] 将线捕捉到现有帽子

[复制链接]

6

主题

23

帖子

17

银币

初来乍到

Rank: 1

铜币
30
发表于 2022-7-7 13:41:16 | 显示全部楼层 |阅读模式
G'day all公司
这是一个非常基本的问题,我相信我应该知道答案。
回复

使用道具 举报

106

主题

1万

帖子

101

银币

顶梁支柱

Rank: 50Rank: 50

铜币
1299
发表于 2022-7-7 14:01:58 | 显示全部楼层
舱口边界HB我记不起它是否是Express的一部分
 
无论如何,这里有一个图案填充边界的副本。lsp
 
  1. ;;; HATCHB.LSP ver 2.1
  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-2004 JTB World, All Rights Reserved
  7. ;;; Website: www.jtbworld.com
  8. ;;; E-mail: info@jtbworld.com
  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. ;;; Tested on AutoCAD r14, 2000, 2000i, 2002, 2004, 2005
  25. ;;; should be working on older versions too.
  26. (defun c:hb (/     es    blay  ed1   ed2   loops1      bptf  part
  27.             et    noe   plist ic    bul   nr    ang1  ang2  obj *ModelSpace* *PaperSpace*
  28.             space cw errexit undox olderr oldcmdecho ss1 lastent en1 en2 ss lwp
  29.             list->variantArray 3dPoint->2dPoint A2k ent i ss2
  30.             knot-list controlpoint-list kn cn pos xv bot area hst
  31.            )
  32. (setq A2k (>= (substr (getvar "ACADVER") 1 2) "15"))
  33. (if A2k
  34.   (progn
  35.     (defun list->variantArray (ptsList / arraySpace sArray)
  36.       (setq arraySpace
  37.       (vlax-make-safearray
  38.         vlax-vbdouble
  39.         (cons 0 (- (length ptsList) 1))
  40.       )
  41.       )
  42.       (setq sArray (vlax-safearray-fill arraySpace ptsList))
  43.       (vlax-make-variant sArray)
  44.     )
  45.     (defun areaOfObject (en / curve area)
  46.       (if en
  47. (if A2k
  48.    (progn
  49.      (setq curve (vlax-ename->vla-object en))
  50.      (if
  51.        (vl-catch-all-error-p
  52.          (setq
  53.            area
  54.             (vl-catch-all-apply 'vlax-curve-getArea (list curve))
  55.          )
  56.        )
  57.         nil
  58.         area
  59.      )
  60.    )
  61.    (progn
  62.      (command "._area" "_O" en)
  63.      (getvar "area")
  64.    )
  65. )
  66.       )
  67.     )
  68.   )
  69. )
  70. (if A2k
  71. (defun 3dPoint->2dPoint (3dpt)
  72.    (list (float (car 3dpt)) (float (cadr 3dpt)))
  73. )
  74. )
  75. (defun errexit (s)
  76.    (princ "\nError:  ")
  77.    (princ s)
  78.    (restore)
  79. )
  80. (defun undox ()
  81.    (command "._ucs" "_p")
  82.    (command "._undo" "_E")
  83.    (setvar "cmdecho" oldcmdecho)
  84.    (setq *error* olderr)
  85.    (princ)
  86. )
  87. (setq olderr  *error*
  88.        restore undox
  89.        *error* errexit
  90. )
  91. (setq oldcmdecho (getvar "cmdecho"))
  92. (setvar "cmdecho" 0)
  93. (command "._UNDO" "_BE")
  94. (if A2k (progn
  95.    (vl-load-com)
  96.    (setq *ModelSpace* (vla-get-ModelSpace
  97.                         (vla-get-ActiveDocument (vlax-get-acad-object))
  98.                       )
  99.          *PaperSpace* (vla-get-PaperSpace
  100.                         (vla-get-ActiveDocument (vlax-get-acad-object))
  101.                       )
  102.    ))
  103. )
  104. ; For testing purpose
  105. ; (setq A2k nil)
  106. (if (/= (setq ss2 (ssget '((0 . "HATCH")))) nil)
  107.   (progn
  108.    (setq i 0)
  109.    (setq area 0)
  110.    (setq bMoreLoops nil)
  111.    (while (setq ent (ssname ss2 i))
  112.      (setq ed1 (entget ent))
  113.      (if (not (equal (assoc 210 ed1) '(210 0.0 0.0 1.0))) (princ "\nHatch not in WCS!"))
  114.      (setq xv (cdr (assoc 210 ed1)))
  115.      (command "._ucs" "_w")
  116.      (setq loops1 (cdr (assoc 91 ed1))) ; number of boundary paths (loops)
  117.      (if (and A2k (= (strcase (cdr (assoc 410 ed1))) "MODEL"))
  118.        (setq space *ModelSpace*)
  119.        (setq space *PaperSpace*)
  120.      )
  121.      (repeat loops1
  122.        (setq ed1 (member (assoc 92 ed1) ed1))
  123.        (setq bptf (cdr (car ed1))) ; boundary path type flag
  124.        (setq ic (cdr (assoc 73 ed1))) ; is closed
  125.        (setq noe (cdr (assoc 93 ed1))) ; number of edges
  126. (setq bot (cdr (assoc 92 ed1))) ; boundary type
  127. (setq hst (cdr (assoc 75 ed1))) ; hatch style
  128.        (setq ed1 (member (assoc 72 ed1) ed1))
  129.        (setq bul (cdr (car ed1))) ; bulge
  130.        (setq plist nil)
  131.        (setq blist nil)
  132.        (cond
  133.          ((> (boole 1 bptf 2) 0) ; polyline
  134.           (repeat noe
  135.             (setq ed1 (member (assoc 10 (cdr ed1)) ed1))
  136.             (setq plist (append plist (list (cdr (assoc 10 ed1)))))
  137.             (setq blist (append blist
  138.                                 (if (> bul 0)
  139.                                   (list (cdr (assoc 42 ed1)))
  140.                                   nil
  141.                                 )
  142.                         )
  143.             )
  144.           )
  145.           (if A2k (progn
  146.             (setq polypoints
  147.                    (apply 'append
  148.                           (mapcar '3dPoint->2dPoint plist)
  149.                    )
  150.             )
  151.             (setq VLADataPts (list->variantArray polypoints))
  152.             (setq obj (vla-addLightweightPolyline space VLADataPts))
  153.             (setq nr 0)
  154.             (repeat (length blist)
  155.               (if (/= (nth nr blist) 0)
  156.                 (vla-setBulge obj nr (nth nr blist))
  157.               )
  158.               (setq nr (1+ nr))
  159.             )
  160.             (if (= ic 1)
  161.               (vla-put-closed obj T)
  162.             )
  163.            )
  164.            (progn
  165.              (if (= ic 1)
  166.                (entmake '((0 . "POLYLINE") (66 . 1) (70 . 1)))
  167.                (entmake '((0 . "POLYLINE") (66 . 1)))
  168.              )
  169.              (setq nr 0)
  170.              (repeat (length plist)
  171.                (if (= bul 0)
  172.                  (entmake (list (cons 0 "VERTEX")
  173.                                 (cons 10 (nth nr plist))
  174.                           )
  175.                  )
  176.                  (entmake (list (cons 0 "VERTEX")
  177.                                 (cons 10 (nth nr plist))
  178.                                 (cons 42 (nth nr blist))
  179.                           )
  180.                  )
  181.                )
  182.                (setq nr (1+ nr))
  183.              )
  184.              (entmake '((0 . "SEQEND")))
  185.            )
  186.           )
  187.          )
  188.          (t ; not polyline
  189.           (setq lastent (entlast))
  190.           (setq lwp T)
  191.           (repeat noe
  192.             (setq et (cdr (assoc 72 ed1)))
  193.             (cond
  194.               ((= et 1) ; line
  195.                (setq ed1 (member (assoc 10 (cdr ed1)) ed1))
  196.                (if A2k
  197.                  (vla-AddLine
  198.                    space
  199.                    (vlax-3d-point (cdr (assoc 10 ed1)))
  200.                    (vlax-3d-point (cdr (assoc 11 ed1)))
  201.                  )
  202.                  (entmake
  203.                    (list
  204.                      (cons 0 "LINE")
  205.                      (list 10 (cadr (assoc 10 ed1)) (caddr (assoc 10 ed1)) 0)
  206.                      (list 11 (cadr (assoc 11 ed1)) (caddr (assoc 11 ed1)) 0)
  207.             ;  (cons 210 xv)
  208.                    )
  209.                  )
  210.                )
  211.                (setq ed1 (cddr ed1))
  212.               )
  213.               ((= et 2) ; circular arc
  214.                 (setq ed1 (member (assoc 10 (cdr ed1)) ed1))
  215.                 (setq ang1 (cdr (assoc 50 ed1)))
  216.                 (setq ang2 (cdr (assoc 51 ed1)))
  217.                 (setq cw (cdr (assoc 73 ed1)))
  218.                 (if (and (equal ang1 0 0.00001) (equal ang2 6.28319 0.00001))
  219.                   (progn
  220.                     (if A2k
  221.                       (vla-AddCircle
  222.                         space
  223.                         (vlax-3d-point (cdr (assoc 10 ed1)))
  224.                         (cdr (assoc 40 ed1))
  225.                       )
  226.                       (entmake (list (cons 0 "CIRCLE")
  227.                                      (assoc 10 ed1)
  228.                                      (assoc 40 ed1)
  229.                                )
  230.                       )
  231.                     )
  232.                     (setq lwp nil)
  233.                   )
  234.                   (if A2k
  235.                     (vla-AddArc
  236.                       space
  237.                       (vlax-3d-point (cdr (assoc 10 ed1)))
  238.                       (cdr (assoc 40 ed1))
  239.                       (if (= cw 0)
  240.                         (- 0 ang2)
  241.                         ang1
  242.                       )
  243.                       (if (= cw 0)
  244.                         (- 0 ang1)
  245.                         ang2
  246.                       )
  247.                     )
  248.                     (entmake (list (cons 0 "ARC")
  249.                                    (assoc 10 ed1)
  250.                                    (assoc 40 ed1)
  251.                                    (cons 50
  252.                                          (if (= cw 0)
  253.                                            (- 0 ang2)
  254.                                            ang1
  255.                                          )
  256.                                    )
  257.                                    (cons 51
  258.                                          (if (= cw 0)
  259.                                            (- 0 ang1)
  260.                                            ang2
  261.                                          )
  262.                                    )
  263.                              )
  264.                     )
  265.                   )
  266.                 )
  267.                 (setq ed1 (cddddr ed1))
  268.               )
  269.               ((= et 3) ; elliptic arc
  270.                (setq ed1 (member (assoc 10 (cdr ed1)) ed1))
  271.                (setq ang1 (cdr (assoc 50 ed1)))
  272.                (setq ang2 (cdr (assoc 51 ed1)))
  273.                (setq cw (cdr (assoc 73 ed1)))
  274.                (if A2k (progn
  275.                  (setq obj (vla-AddEllipse
  276.                              space
  277.                              (vlax-3d-point (cdr (assoc 10 ed1)))
  278.                              (vlax-3d-point (cdr (assoc 11 ed1)))
  279.                              (cdr (assoc 40 ed1))
  280.                            )
  281.                  )
  282.                  (vla-put-startangle obj (if (= cw 0) (- 0 ang2) ang1))
  283.                  (vla-put-endangle obj (if (= cw 0) (- 0 ang1) ang2))
  284.                 )
  285.                 (princ "\nElliptic arc not supported!")
  286.                )
  287.                (setq lwp nil)
  288.               )
  289.               ((= et 4) ; spline
  290.                (setq ed1 (member (assoc 94 (cdr ed1)) ed1))
  291.                (setq knot-list nil)
  292.                (setq controlpoint-list nil)
  293.         (setq kn (cdr (assoc 95 ed1)))
  294.                (setq cn (cdr (assoc 96 ed1)))
  295.                (setq pos (vl-position (assoc 40 ed1) ed1))
  296.                (repeat kn
  297.                  (setq knot-list (cons (cons 40 (cdr (nth pos ed1))) knot-list))
  298.                  (setq pos (1+ pos))
  299.                )
  300.                (setq pos (vl-position (assoc 10 ed1) ed1))
  301.                (repeat cn
  302.                  (setq controlpoint-list (cons (cons 10 (cdr (nth pos ed1))) controlpoint-list))
  303.                  (setq pos (1+ pos))
  304.                )
  305.                (setq knot-list (reverse knot-list))
  306.                (setq controlpoint-list (reverse controlpoint-list))
  307.                (entmake (append
  308.                        (list '(0 . "SPLINE"))
  309.                               (list (cons 100 "AcDbEntity"))
  310.                               (list (cons 100 "AcDbSpline"))
  311.                               (list (cons 70 (+ 1 8 (* 2 (cdr (assoc 74 ed1))) (* 4 (cdr (assoc 73 ed1))))))
  312.                               (list (cons 71 (cdr (assoc 94 ed1))))
  313.                               (list (cons 72 kn))
  314.                               (list (cons 73 cn))
  315.                               knot-list
  316.                               controlpoint-list
  317.                      )
  318.                )
  319.         (setq ed1 (member (assoc 10 ed1) ed1))
  320.                (setq lwp nil)
  321.               )
  322.             ) ; end cond
  323.           ) ; end repeat noe
  324.           (if lwp (progn
  325.             (setq en1 (entnext lastent))
  326.             (setq ss (ssadd))
  327.             (ssadd en1 ss)
  328.             (while (setq en2 (entnext en1))
  329.               (ssadd en2 ss)
  330.               (setq en1 en2)
  331.             )
  332.      (if (= (getvar "peditaccept") 1)
  333.               (command "_.pedit" (entlast) "_J" ss "" "")
  334.        (command "_.pedit" (entlast) "_Y" "_J" ss "" "")
  335.      )
  336.          ))
  337.          ) ; end t
  338.        ) ; end cond
  339. ;        Tries to get the area on islands but it's not clear how to know if an island is filled or not
  340. ;        and if it should be substracted or added to the total area.
  341. ;        (if (or (= bot 0) (= (boole 1 bot 1) 1)) (setq area (+ area (areaOfObject (entlast)))))
  342. ;        (if (and (/= hst 1) (/= bot 0) (= (boole 1 bot 1) 0)) (setq area (- area (areaOfObject (entlast)))))
  343. ;        (princ "\n") (princ bot) (princ "\n") (princ hst) (princ "\n")
  344. ;        (princ (areaOfObject (entlast)))
  345.      ) ; end repeat loops1
  346.      (if (= loops1 1) (setq area (+ area (areaOfObject (entlast)))) (setq bMoreLoops T))
  347.      (setq i (1+ i))
  348.    )
  349.   )
  350. )
  351. (if (and area (not bMoreLoops)) (progn
  352.    (princ "\nTotal Area = ")
  353.    (princ area)
  354. ))
  355. (restore)
  356. (princ)
  357. )
回复

使用道具 举报

7

主题

708

帖子

701

银币

初来乍到

Rank: 1

铜币
35
发表于 2022-7-7 14:17:17 | 显示全部楼层
我认为这是一个新记录。OP中的问答。
回复

使用道具 举报

6

主题

122

帖子

118

银币

初来乍到

Rank: 1

铜币
30
发表于 2022-7-7 14:39:52 | 显示全部楼层
以防万一有人来到这个帖子并想知道解决方案:
 
[列表=1]
  • 选择图案填充
  • 右键单击
  • 选择“生成边界”
    [/列表]
    144123bngygg5vkgxxyggu.png
  • 回复

    使用道具 举报

    12

    主题

    395

    帖子

    384

    银币

    初露锋芒

    Rank: 3Rank: 3Rank: 3

    铜币
    60
    发表于 2022-7-7 14:55:44 | 显示全部楼层
    如果使用功能区,则在选择图案填充时,功能区也在其中。
    回复

    使用道具 举报

    发表回复

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

    本版积分规则

    • 微信公众平台

    • 扫描访问手机版

    • 点击图片下载手机App

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

    GMT+8, 2025-3-7 06:30 , Processed in 0.334923 second(s), 64 queries .

    © 2020-2025 乐筑天下

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