找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 913|回复: 4

[转贴]:跟据已有hatch生成hatch边界

[复制链接]
发表于 2002-9-16 20:35:40 | 显示全部楼层 |阅读模式

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

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

×
  1. [font=courier]
  2. ;;; HATCHB.LSP ver 1.6
  3. ;;; Recreates hatch boundary by selecting a hatch
  4. ;;; Boundary is created in current layer/color/linetype in WCS
  5. ;;; By Jimmy Bergmark
  6. ;;; Copyright (C) 1997-2002 JTB World, All Rights Reserved
  7. ;;; Website: [url]www.jtbworld.com[/url] / [url]http://jtbworld.vze.com[/url]
  8. ;;; E-mail: [email]info@jtbworld.com[/email] / [email]jtbworld@hotmail.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. ;;; Tested on AutoCAD r14, 2000, 2000i, 2002
  21. ;;; should be working on older versions too.

  22. (defun c:hatchb        (/            es               blay          ed1             ed2
  23.                  loops1            bptf       part          et             noe
  24.                  plist            ic               bul          nr             ang1
  25.                  ang2            obj               *ModelSpace*             *PaperSpace*
  26.                  space            cw               errexit          undox             olderr
  27.                  oldcmdecho ss1               lastent          en1             en2
  28.                  ss            lwp               list->variantArray    3dPoint->2dPoint
  29.                  A2k            ent               i          ss2             knot-list
  30.                  controlpoint-list     kn          cn             pos
  31.                  xv
  32.                 )
  33.   (setq A2k (wcmatch (getvar "ACADVER") "15*"))
  34.   (if A2k
  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.   )
  46.   (if A2k
  47.     (defun 3dPoint->2dPoint (3dpt)
  48.       (list (float (car 3dpt)) (float (cadr 3dpt)))
  49.     )
  50.   )
  51.   (defun errexit (s) (princ "\nError:  ") (princ s) (restore))
  52.   (defun undox ()
  53.     (command "._ucs" "_p")
  54.     (command "._undo" "_E")
  55.     (setvar "cmdecho" oldcmdecho)
  56.     (setq *error* olderr)
  57.     (princ)
  58.   )
  59.   (setq        olderr        *error*
  60.         restore        undox
  61.         *error*        errexit
  62.   )
  63.   (setq oldcmdecho (getvar "cmdecho"))
  64.   (setvar "cmdecho" 0)
  65.   (command "._UNDO" "_BE")
  66.   (if A2k
  67.     (progn (vl-load-com)
  68.            (setq *ModelSpace* (vla-get-ModelSpace
  69.                                 (vla-get-ActiveDocument (vlax-get-acad-object))
  70.                               )
  71.                  *PaperSpace* (vla-get-PaperSpace
  72.                                 (vla-get-ActiveDocument (vlax-get-acad-object))
  73.                               )
  74.            )
  75.     )
  76.   )                                        ; For testing purpose
  77.                                         ; (setq A2k nil)
  78.   (if (/= (setq ss2 (ssget '((0 . "HATCH")))) nil)
  79.     (progn
  80.       (setq i 0)
  81.       (while (setq ent (ssname ss2 i))
  82.         (setq ed1 (entget ent))
  83.         (if (not (equal (assoc 210 ed1) '(210 0.0 0.0 1.0)))
  84.           (princ "\nHatch not in WCS!")
  85.         )
  86.         (setq xv (cdr (assoc 210 ed1)))
  87.         (command "._ucs" "_w")
  88.         (setq loops1 (cdr (assoc 91 ed1))) ; number of boundary paths (loops)
  89.         (if (and A2k (= (strcase (cdr (assoc 410 ed1))) "MODEL"))
  90.           (setq space *ModelSpace*)
  91.           (setq space *PaperSpace*)
  92.         )
  93.         (repeat        loops1
  94.           (setq ed1 (member (assoc 92 ed1) ed1))
  95.           (setq bptf (cdr (car ed1)))        ; boundary path type flag
  96.           (setq ic (cdr (assoc 73 ed1))) ; is closed
  97.           (setq noe (cdr (assoc 93 ed1))) ; number of edges
  98.           (setq ed1 (member (assoc 72 ed1) ed1))
  99.           (setq bul (cdr (car ed1)))        ; bulge
  100.           (setq plist nil)
  101.           (setq blist nil)
  102.           (cond
  103.             ((> (boole 1 bptf 2) 0)        ; polyline
  104.              (repeat noe
  105.                (setq ed1 (member (assoc 10 (cdr ed1)) ed1))
  106.                (setq plist (append plist (list (cdr (assoc 10 ed1)))))
  107.                (setq blist (append blist
  108.                                    (if (> bul 0)
  109.                                      (list (cdr (assoc 42 ed1)))
  110.                                      nil
  111.                                    )
  112.                            )
  113.                )
  114.              )
  115.              (if A2k
  116.                (progn (setq polypoints
  117.                              (apply 'append (mapcar '3dPoint->2dPoint plist))
  118.                       )
  119.                       (setq VLADataPts (list->variantArray polypoints))
  120.                       (setq obj (vla-addLightweightPolyline space VLADataPts))
  121.                       (setq nr 0)
  122.                       (repeat (length blist)
  123.                         (if (/= (nth nr blist) 0)
  124.                           (vla-setBulge obj nr (nth nr blist))
  125.                         )
  126.                         (setq nr (1+ nr))
  127.                       )
  128.                       (if (= ic 1)
  129.                         (vla-put-closed obj T)
  130.                       )
  131.                )
  132.                (progn
  133.                  (if (= ic 1)
  134.                    (entmake '((0 . "POLYLINE") (66 . 1) (70 . 1)))
  135.                    (entmake '((0 . "POLYLINE") (66 . 1)))
  136.                  )
  137.                  (setq nr 0)
  138.                  (repeat (length plist)
  139.                    (if (= bul 0)
  140.                      (entmake (list (cons 0 "VERTEX") (cons 10 (nth nr plist))))
  141.                      (entmake (list (cons 0 "VERTEX")
  142.                                     (cons 10 (nth nr plist))
  143.                                     (cons 42 (nth nr blist))
  144.                               )
  145.                      )
  146.                    )
  147.                    (setq nr (1+ nr))
  148.                  )
  149.                  (entmake '((0 . "SEQEND")))
  150.                )
  151.              )
  152.             )
  153.             (t                                ; not polyline
  154.              (setq lastent (entlast))
  155.              (setq lwp T)
  156.              (repeat noe
  157.                (setq et (cdr (assoc 72 ed1)))
  158.                (cond
  159.                  ((= et 1)                ; line
  160.                   (setq ed1 (member (assoc 10 (cdr ed1)) ed1))
  161.                   (if A2k
  162.                     (vla-AddLine
  163.                       space
  164.                       (vlax-3d-point (cdr (assoc 10 ed1)))
  165.                       (vlax-3d-point (cdr (assoc 11 ed1)))
  166.                     )
  167.                     (entmake
  168.                       (list
  169.                         (cons 0 "LINE")
  170.                         (list 10 (cadr (assoc 10 ed1)) (caddr (assoc 10 ed1)) 0)
  171.                         (list 11 (cadr (assoc 11 ed1)) (caddr (assoc 11 ed1)) 0)
  172.                                         ;  (cons 210 xv)
  173.                       )
  174.                     )
  175.                   )
  176.                   (setq ed1 (cddr ed1))
  177.                  )
  178.                  ((= et 2)                ; circular arc
  179.                   (setq ed1 (member (assoc 10 (cdr ed1)) ed1))
  180.                   (setq ang1 (cdr (assoc 50 ed1)))
  181.                   (setq ang2 (cdr (assoc 51 ed1)))
  182.                   (setq cw (cdr (assoc 73 ed1)))
  183.                   (if (equal ang2 6.28319 0.00001)
  184.                     (progn
  185.                       (if A2k
  186.                         (vla-AddCircle
  187.                           space
  188.                           (vlax-3d-point (cdr (assoc 10 ed1)))
  189.                           (cdr (assoc 40 ed1))
  190.                         )
  191.                         (entmake
  192.                           (list (cons 0 "CIRCLE") (assoc 10 ed1) (assoc 40 ed1))
  193.                         )
  194.                       )
  195.                       (setq lwp nil)
  196.                     )
  197.                     (if        A2k
  198.                       (vla-AddArc
  199.                         space
  200.                         (vlax-3d-point (cdr (assoc 10 ed1)))
  201.                         (cdr (assoc 40 ed1))
  202.                         (if (= cw 0)
  203.                           (- 0 ang2)
  204.                           ang1
  205.                         )
  206.                         (if (= cw 0)
  207.                           (- 0 ang1)
  208.                           ang2
  209.                         )
  210.                       )
  211.                       (entmake (list (cons 0 "ARC")
  212.                                      (assoc 10 ed1)
  213.                                      (assoc 40 ed1)
  214.                                      (cons 50
  215.                                            (if (= cw 0)
  216.                                              (- 0 ang2)
  217.                                              ang1
  218.                                            )
  219.                                      )
  220.                                      (cons 51
  221.                                            (if (= cw 0)
  222.                                              (- 0 ang1)
  223.                                              ang2
  224.                                            )
  225.                                      )
  226.                                )
  227.                       )
  228.                     )
  229.                   )
  230.                   (setq ed1 (cddddr ed1))
  231.                  )
  232.                  ((= et 3)                ; elliptic arc
  233.                   (setq ed1 (member (assoc 10 (cdr ed1)) ed1))
  234.                   (setq ang1 (cdr (assoc 50 ed1)))
  235.                   (setq ang2 (cdr (assoc 51 ed1)))
  236.                   (setq cw (cdr (assoc 73 ed1)))
  237.                   (if A2k
  238.                     (progn (setq obj (vla-AddEllipse
  239.                                        space
  240.                                        (vlax-3d-point (cdr (assoc 10 ed1)))
  241.                                        (vlax-3d-point (cdr (assoc 11 ed1)))
  242.                                        (cdr (assoc 40 ed1))
  243.                                      )
  244.                            )
  245.                            (vla-put-startangle
  246.                              obj
  247.                              (if (= cw 0)
  248.                                (- 0 ang2)
  249.                                ang1
  250.                              )
  251.                            )
  252.                            (vla-put-endangle
  253.                              obj
  254.                              (if (= cw 0)
  255.                                (- 0 ang1)
  256.                                ang2
  257.                              )
  258.                            )
  259.                     )
  260.                     (princ "\nElliptic arc not supported!")
  261.                   )
  262.                   (setq lwp nil)
  263.                  )
  264.                  ((= et 4)                ; spline
  265.                   (setq ed1 (member (assoc 94 (cdr ed1)) ed1))
  266.                   (setq knot-list nil)
  267.                   (setq controlpoint-list nil)
  268.                   (setq kn (cdr (assoc 95 ed1)))
  269.                   (setq cn (cdr (assoc 96 ed1)))
  270.                   (setq pos (vl-position (assoc 40 ed1) ed1))
  271.                   (repeat kn
  272.                     (setq
  273.                       knot-list        (cons (cons 40 (cdr (nth pos ed1))) knot-list)
  274.                     )
  275.                     (setq pos (1+ pos))
  276.                   )
  277.                   (setq pos (vl-position (assoc 10 ed1) ed1))
  278.                   (repeat cn
  279.                     (setq controlpoint-list
  280.                            (cons (cons 10 (cdr (nth pos ed1)))
  281.                                  controlpoint-list
  282.                            )
  283.                     )
  284.                     (setq pos (1+ pos))
  285.                   )
  286.                   (setq knot-list (reverse knot-list))
  287.                   (setq controlpoint-list (reverse controlpoint-list))
  288.                   (entmake (append (list '(0 . "SPLINE"))
  289.                                    (list (cons 100 "AcDbEntity"))
  290.                                    (list (cons 100 "AcDbSpline"))
  291.                                    (list (cons 70
  292.                                                (+ 1
  293.                                                   8
  294.                                                   (* 2 (cdr (assoc 74 ed1)))
  295.                                                   (* 4 (cdr (assoc 73 ed1)))
  296.                                                )
  297.                                          )
  298.                                    )
  299.                                    (list (cons 71 (cdr (assoc 94 ed1))))
  300.                                    (list (cons 72 kn))
  301.                                    (list (cons 73 cn))
  302.                                    knot-list
  303.                                    controlpoint-list
  304.                            )
  305.                   )
  306.                   (setq ed1 (member (assoc 10 ed1) ed1))
  307.                   (setq lwp nil)
  308.                  )
  309.                )                        ; end cond
  310.              )                                ; end repeat noe
  311.              (if lwp
  312.                (progn
  313.                  (setq en1 (entnext lastent))
  314.                  (setq ss (ssadd))
  315.                  (ssadd en1 ss)
  316.                  (while (setq en2 (entnext en1)) (ssadd en2 ss) (setq en1 en2))
  317.                  (command "_.pedit" (entlast) "_Y" "_J" ss "" "")
  318.                )
  319.              )
  320.             )                                ; end t
  321.           )                                ; end cond
  322.         )                                ; end repeat loops1
  323.         (setq i (1+ i))
  324.       )
  325.     )
  326.   )
  327.   (restore)
  328.   (princ)
  329. )
  330. [/font]
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
发表于 2003-1-11 21:10:35 | 显示全部楼层
非常实用的一个LISP函数,解决了我的一个大问题,感谢的同时,建议晓动给秋枫斑竹加分,虽然积分对秋枫已经没什么意义,但能体现对论坛的贡献!
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

发表于 2003-1-11 22:09:47 | 显示全部楼层
哎呀,看似简单的一个问题实现起来却不简单哟。谢谢秋哥!
从哪儿找到的?象是老外便的吧。
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

 楼主| 发表于 2003-1-11 23:15:51 | 显示全部楼层
http://jtbworld.vze.com/

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

使用道具 举报

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

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-5-6 01:43 , Processed in 0.370505 second(s), 39 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

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