反画出填充边界线,并关联边界线与填充!(申请编LISP)
<p>如题,有一CAD2000格式的文件,已经有填充图案,可没有边界线,如何反画出填充边界线,并关联边界线与填充!期待高手编LISP!!!</p><p>(我知道CAD2006版本有,可不知道怎么提出里面的lisp功能文件)</p> <p>;;; HATCHB.LSP ver 2.0 <br/>;;; Recreates hatch boundary by selecting a hatch <br/>;;; Boundary is created in current layer/color/linetype in WCS <br/>;;; By Jimmy Bergmark <br/>;;; Copyright (C) 1997-2003 JTB World, All Rights Reserved <br/>;;; Website: www.jtbworld.com <br/>;;; E-mail: info@jtbworld.com <br/>;;; 2000-02-12 - First release <br/>;;; 2000-03-27 - Counterclockwise arc's and ellipse's fixed <br/>;;; Objects created joined to lwpolyline if possible <br/>;;; Error-handling, undo of command <br/>;;; Can handle PLINETYPE = 0,1,2 <br/>;;; 2000-03-30 - Integrating hatchb and hatchb14 <br/>;;; Selection of many hatches <br/>;;; Splines supported if closed. <br/>;;; 2001-04-02 - Fixed bug with entmake of line with no Z for r14 <br/>;;; 2001-07-31 - Removed an irritating semicolon to enable polylines to be created. <br/>;;; 2001-10-04 - Changed mail and homepage so it's easy to find when new versions comes up. <br/>;;; 2003-02-06 - Minor fix <br/>;;; 2003-02-17 - Area returned if no islands is found since it's not consistant <br/>;;; 2003-05-19 - Fix to take PEDITACCEPT variable used in AutoCAD 2004 into account <br/>;;; Tested on AutoCAD r14, 2000, 2000i, 2002, 2004 <br/>;;; should be working on older versions too. </p><p>(defun c:hb () (c:hatchb)) ; this line can be commented out if there is an existing command called hb <br/>(defun c:hatchb (/ es blay ed1 ed2 loops1 bptf part <br/> et noe plist ic bul nr ang1 ang2 obj *ModelSpace* *PaperSpace* <br/> space cw errexit undox olderr oldcmdecho ss1 lastent en1 en2 ss lwp <br/> list->variantArray 3dPoint->2dPoint A2k ent i ss2 <br/> knot-list controlpoint-list kn cn pos xv bot area hst <br/> ) <br/>(setq A2k (>= (substr (getvar "ACADVER") 1 2) "15")) <br/>(if A2k <br/> (progn <br/> (defun list->variantArray (ptsList / arraySpace sArray) <br/> (setq arraySpace <br/> (vlax-make-safearray <br/> vlax-vbdouble <br/> (cons 0 (- (length ptsList) 1)) <br/> ) <br/> ) <br/> (setq sArray (vlax-safearray-fill arraySpace ptsList)) <br/> (vlax-make-variant sArray) <br/> ) <br/> (defun areaOfObject (en / curve area) <br/> (if en <br/> (if A2k <br/> (progn <br/> (setq curve (vlax-ename->vla-object en)) <br/> (if <br/> (vl-catch-all-error-p <br/> (setq <br/> area <br/> (vl-catch-all-apply 'vlax-curve-getArea (list curve)) <br/> ) <br/> ) <br/> nil <br/> area <br/> ) <br/> ) <br/> (progn <br/> (command "._area" "_O" en) <br/> (getvar "area") <br/> ) <br/> ) <br/> ) <br/> ) <br/> ) <br/>) <br/>(if A2k <br/> (defun 3dPoint->2dPoint (3dpt) <br/> (list (float (car 3dpt)) (float (cadr 3dpt))) <br/> ) <br/>) </p><p> (defun errexit (s) <br/> (princ "\nError: ") <br/> (princ s) <br/> (restore) <br/> ) </p><p> (defun undox () <br/> (command "._ucs" "_p") <br/> (command "._undo" "_E") <br/> (setvar "cmdecho" oldcmdecho) <br/> (setq *error* olderr) <br/> (princ) <br/> ) </p><p> (setq olderr *error* <br/> restore undox <br/> *error* errexit <br/> ) <br/> (setq oldcmdecho (getvar "cmdecho")) <br/> (setvar "cmdecho" 0) <br/> (command "._UNDO" "_BE") <br/> (if A2k (progn <br/> (vl-load-com) <br/> (setq *ModelSpace* (vla-get-ModelSpace <br/> (vla-get-ActiveDocument (vlax-get-acad-object)) <br/> ) <br/> *PaperSpace* (vla-get-PaperSpace <br/> (vla-get-ActiveDocument (vlax-get-acad-object)) <br/> ) <br/> )) <br/> ) </p><p><br/>; For testing purpose <br/>; (setq A2k nil) <br/> <br/> (if (/= (setq ss2 (ssget '((0 . "HATCH")))) nil) <br/> (progn <br/> (setq i 0) <br/> (setq area 0) <br/> (setq bMoreLoops nil) <br/> (while (setq ent (ssname ss2 i)) <br/> (setq ed1 (entget ent)) <br/> (if (not (equal (assoc 210 ed1) '(210 0.0 0.0 1.0))) (princ "\nHatch not in WCS!")) <br/> (setq xv (cdr (assoc 210 ed1))) <br/> (command "._ucs" "_w") <br/> (setq loops1 (cdr (assoc 91 ed1))) ; number of boundary paths (loops) <br/> (if (and A2k (= (strcase (cdr (assoc 410 ed1))) "MODEL")) <br/> (setq space *ModelSpace*) <br/> (setq space *PaperSpace*) <br/> ) <br/> (repeat loops1 <br/> (setq ed1 (member (assoc 92 ed1) ed1)) <br/> (setq bptf (cdr (car ed1))) ; boundary path type flag <br/> (setq ic (cdr (assoc 73 ed1))) ; is closed <br/> (setq noe (cdr (assoc 93 ed1))) ; number of edges <br/> (setq bot (cdr (assoc 92 ed1))) ; boundary type <br/> (setq hst (cdr (assoc 75 ed1))) ; hatch style <br/> (setq ed1 (member (assoc 72 ed1) ed1)) <br/> (setq bul (cdr (car ed1))) ; bulge <br/> (setq plist nil) <br/> (setq blist nil) <br/> (cond <br/> ((> (boole 1 bptf 2) 0) ; polyline <br/> (repeat noe <br/> (setq ed1 (member (assoc 10 (cdr ed1)) ed1)) <br/> (setq plist (append plist (list (cdr (assoc 10 ed1))))) <br/> (setq blist (append blist <br/> (if (> bul 0) <br/> (list (cdr (assoc 42 ed1))) <br/> nil <br/> ) <br/> ) <br/> ) <br/> ) <br/> (if A2k (progn <br/> (setq polypoints <br/> (apply 'append <br/> (mapcar '3dPoint->2dPoint plist) <br/> ) <br/> ) <br/> (setq VLADataPts (list->variantArray polypoints)) <br/> (setq obj (vla-addLightweightPolyline space VLADataPts)) <br/> (setq nr 0) <br/> (repeat (length blist) <br/> (if (/= (nth nr blist) 0) <br/> (vla-setBulge obj nr (nth nr blist)) <br/> ) <br/> (setq nr (1+ nr)) <br/> ) <br/> (if (= ic 1) <br/> (vla-put-closed obj T) <br/> ) <br/> ) <br/> (progn <br/> (if (= ic 1) <br/> (entmake '((0 . "POLYLINE") (66 . 1) (70 . 1))) <br/> (entmake '((0 . "POLYLINE") (66 . 1))) <br/> ) <br/> (setq nr 0) <br/> (repeat (length plist) <br/> (if (= bul 0) <br/> (entmake (list (cons 0 "VERTEX") <br/> (cons 10 (nth nr plist)) <br/> ) <br/> ) <br/> (entmake (list (cons 0 "VERTEX") <br/> (cons 10 (nth nr plist)) <br/> (cons 42 (nth nr blist)) <br/> ) <br/> ) <br/> ) <br/> (setq nr (1+ nr)) <br/> ) <br/> (entmake '((0 . "SEQEND"))) <br/> ) <br/> ) <br/> ) <br/> (t ; not polyline <br/> (setq lastent (entlast)) <br/> (setq lwp T) <br/> (repeat noe <br/> (setq et (cdr (assoc 72 ed1))) <br/> (cond <br/> ((= et 1) ; line <br/> (setq ed1 (member (assoc 10 (cdr ed1)) ed1)) <br/> (if A2k <br/> (vla-AddLine <br/> space <br/> (vlax-3d-point (cdr (assoc 10 ed1))) <br/> (vlax-3d-point (cdr (assoc 11 ed1))) <br/> ) <br/> (entmake <br/> (list <br/> (cons 0 "LINE") <br/> (list 10 (cadr (assoc 10 ed1)) (caddr (assoc 10 ed1)) 0) <br/> (list 11 (cadr (assoc 11 ed1)) (caddr (assoc 11 ed1)) 0) <br/> ; (cons 210 xv) <br/> ) <br/> ) <br/> ) <br/> (setq ed1 (cddr ed1)) <br/> ) <br/> ((= et 2) ; circular arc <br/> (setq ed1 (member (assoc 10 (cdr ed1)) ed1)) <br/> (setq ang1 (cdr (assoc 50 ed1))) <br/> (setq ang2 (cdr (assoc 51 ed1))) <br/> (setq cw (cdr (assoc 73 ed1))) <br/> (if (equal ang2 6.28319 0.00001) <br/> (progn <br/> (if A2k <br/> (vla-AddCircle <br/> space <br/> (vlax-3d-point (cdr (assoc 10 ed1))) <br/> (cdr (assoc 40 ed1)) <br/> ) <br/> (entmake (list (cons 0 "CIRCLE") <br/> (assoc 10 ed1) <br/> (assoc 40 ed1) <br/> ) <br/> ) <br/> ) <br/> (setq lwp nil) <br/> ) <br/> (if A2k <br/> (vla-AddArc <br/> space <br/> (vlax-3d-point (cdr (assoc 10 ed1))) <br/> (cdr (assoc 40 ed1)) <br/> (if (= cw 0) <br/> (- 0 ang2) <br/> ang1 <br/> ) <br/> (if (= cw 0) <br/> (- 0 ang1) <br/> ang2 <br/> ) <br/> ) <br/> (entmake (list (cons 0 "ARC") <br/> (assoc 10 ed1) <br/> (assoc 40 ed1) <br/> (cons 50 <br/> (if (= cw 0) <br/> (- 0 ang2) <br/> ang1 <br/> ) <br/> ) <br/> (cons 51 <br/> (if (= cw 0) <br/> (- 0 ang1) <br/> ang2 <br/> ) <br/> ) <br/> ) <br/> ) <br/> ) <br/> ) <br/> (setq ed1 (cddddr ed1)) <br/> ) <br/> ((= et 3) ; elliptic arc <br/> (setq ed1 (member (assoc 10 (cdr ed1)) ed1)) <br/> (setq ang1 (cdr (assoc 50 ed1))) <br/> (setq ang2 (cdr (assoc 51 ed1))) <br/> (setq cw (cdr (assoc 73 ed1))) <br/> (if A2k (progn <br/> (setq obj (vla-AddEllipse <br/> space <br/> (vlax-3d-point (cdr (assoc 10 ed1))) <br/> (vlax-3d-point (cdr (assoc 11 ed1))) <br/> (cdr (assoc 40 ed1)) <br/> ) <br/> ) <br/> (vla-put-startangle obj (if (= cw 0) (- 0 ang2) ang1)) <br/> (vla-put-endangle obj (if (= cw 0) (- 0 ang1) ang2)) <br/> ) <br/> (princ "\nElliptic arc not supported!") <br/> ) <br/> (setq lwp nil) <br/> ) <br/> ((= et 4) ; spline <br/> (setq ed1 (member (assoc 94 (cdr ed1)) ed1)) <br/> (setq knot-list nil) <br/> (setq controlpoint-list nil) <br/> (setq kn (cdr (assoc 95 ed1))) <br/> (setq cn (cdr (assoc 96 ed1))) <br/> (setq pos (vl-position (assoc 40 ed1) ed1)) <br/> (repeat kn <br/> (setq knot-list (cons (cons 40 (cdr (nth pos ed1))) knot-list)) <br/> (setq pos (1+ pos)) <br/> ) <br/> (setq pos (vl-position (assoc 10 ed1) ed1)) <br/> (repeat cn <br/> (setq controlpoint-list (cons (cons 10 (cdr (nth pos ed1))) controlpoint-list)) <br/> (setq pos (1+ pos)) <br/> ) <br/> (setq knot-list (reverse knot-list)) <br/> (setq controlpoint-list (reverse controlpoint-list)) <br/> (entmake (append <br/> (list '(0 . "SPLINE")) <br/> (list (cons 100 "AcDbEntity")) <br/> (list (cons 100 "AcDbSpline")) <br/> (list (cons 70 (+ 1 8 (* 2 (cdr (assoc 74 ed1))) (* 4 (cdr (assoc 73 ed1)))))) <br/> (list (cons 71 (cdr (assoc 94 ed1)))) <br/> (list (cons 72 kn)) <br/> (list (cons 73 cn)) <br/> knot-list <br/> controlpoint-list <br/> ) <br/> ) <br/> (setq ed1 (member (assoc 10 ed1) ed1)) <br/> (setq lwp nil) <br/> ) <br/> ) ; end cond <br/> ) ; end repeat noe <br/> (if lwp (progn <br/> (setq en1 (entnext lastent)) <br/> (setq ss (ssadd)) <br/> (ssadd en1 ss) <br/> (while (setq en2 (entnext en1)) <br/> (ssadd en2 ss) <br/> (setq en1 en2) <br/> ) <br/> (if (= (getvar "peditaccept") 1) <br/> (command "_.pedit" (entlast) "_J" ss "" "") <br/> (command "_.pedit" (entlast) "_Y" "_J" ss "" "") <br/> ) <br/> )) </p><p> ) ; end t <br/> ) ; end cond <br/>; Tries to get the area on islands but it's not clear how to know if an island is filled or not <br/>; and if it should be substracted or added to the total area. <br/>; (if (or (= bot 0) (= (boole 1 bot 1) 1)) (setq area (+ area (areaOfObject (entlast))))) <br/>; (if (and (/= hst 1) (/= bot 0) (= (boole 1 bot 1) 0)) (setq area (- area (areaOfObject (entlast))))) <br/>; (princ "\n") (princ bot) (princ "\n") (princ hst) (princ "\n") <br/>; (princ (areaOfObject (entlast))) <br/> ) ; end repeat loops1 <br/> (if (= loops1 1) (setq area (+ area (areaOfObject (entlast)))) (setq bMoreLoops T)) <br/> (setq i (1+ i)) <br/> ) <br/> ) <br/> ) <br/> (if (and area (not bMoreLoops)) (progn <br/> (princ "\nTotal Area = ") <br/> (princ area) <br/> )) <br/> (restore) <br/> (princ) <br/>)</p> <p>在FSXM那里找到一个绘制<font color="#ff00ff">关联填充边界</font>,很好用。</p><p> </p>
<p>可惜没有源码。</p> zgyxn 发表于 2007-7-19 10:30
;;; HATCHB.LSP ver 2.0 ;;; Recreates hatch boundary by selecting a hatch ;;; Boundary is created in...
大神的历害,有源码,有能实现功能,,顶起 我觉得这是有难度的,在网上看到关于填充生成边界的帖子,都不是很完美!! 这个功能的确很难,要做到像R2006那样,估计得吃透图案填充的dxf码。 <p></p><p>湘源控规---->工具--->已经能够反画出填充边界线,并实现关联了!!真是高啊,哪位高人可以把它单独提取出来!!!!</p> jaminth发表于2007-7-15 18:51:00static/image/common/back.gif如题,有一CAD2000格式的文件,已经有填充图案,可没有边界线,如何反画出填充边界线,并关联边界线与填充!期待高手编LISP!!!(我知道CAD2006版本有,可不知道怎么提出里面的lisp功能文件)
<p></p>2006自带的吗?在哪里?还不知道,请说说 <p> </p><p>双击欲反画的填充图案,调出填充工具面板,......按提示操作即可!</p> ;Takes a hatch ename or elist and creates an new associative version of
;the hatch along with new boundary objects.
;Returns the ename of the new hatch if successful.
;
(defun acet-hatch-remake ( e1 / na lst loop loop2 edge )
(if (equal (type e1) 'ENAME)
(setq na e1
e1 (entget na)
);setq then
(setq na (cdr (assoc -1 e1)));setq else
);if
(setq lst (acet-hatch-loop-make e1)) ;; make the boundary edges
(entmake e1) ;; make a copy of the hatch
(setq na (entlast)
e1 (entget na)
e1 (acet-hatch-edge-id-remove-all e1) ;; remove the existing boundary object references
);setq
(acet-hatch-boundary-assoc-db e1 lst T);; add the new ones
(setq e1 (entget na))
(acet-hatch-update na)
na
);defun acet-hatch-remakeacet(就是express tools啦)的函数.参考一下
不用ET行不 <strong><font face="Verdana" color="#da2549">你的文件无痕.怎么用?</font></strong> <p>没办法直接用(如果不装et工具的话)</p><p>仅仅是拿出来参考.不是用来解决问题:P</p>