ectech Posted April 15, 2010 Posted April 15, 2010 Dear all, I would like to create hatch on all polyline in different layer. For example, all polyline on layer 1 create hatch as red color and all polyline on layer 2 create hatch as yellow color.... Is it possible to create it automatically by lisp ? Thanks ! Quote
alanjt Posted April 15, 2010 Posted April 15, 2010 When you say 'hatch on polyline', do you mean hatch within closed polylines? Quote
ectech Posted April 16, 2010 Author Posted April 16, 2010 yes, thank you . hatch within closed polylines Quote
alanjt Posted April 16, 2010 Posted April 16, 2010 Hatching closed polylines isn't terribly difficult. What do you have so far for code? Hint (best way to select your closed LWPolylines): (ssget '((0 . "LWPOLYLINE") (-4 . "<OR") (70 . 1) (70 . 129) (-4 . "OR>"))) Quote
BearDyugin Posted April 16, 2010 Posted April 16, 2010 Hint (best way to select your closed LWPolylines): (ssget '((0 . "LWPOLYLINE") (-4 . "<OR") (70 . 1) (70 . 129) (-4 . "OR>"))) But if ((-1 . <Имя объекта: 7edf4508>) (0 . "LWPOLYLINE") (330 . <Имя объекта: 7ed49cf8>) (5 . "6369") (100 . "AcDbEntity") (67 . 0) (410 . "Model") (8 . "0") (100 . "AcDbPolyline") (90 . 5) [b][color="Red"](70 . 0)[/color][/b] (43 . 0.0) (38 . 0.0) (39 . 0.0) [color="Blue"][b](10 -1632.64 5446.11)[/b][/color] (40 . 0.0) (41 . 0.0) (42 . 0.0) (91 . 0) (10 -330.423 2953.1) (40 . 0.0) (41 . 0.0) (42 . 0.0) (91 . 0) (10 3128.59 4700.92) (40 . 0.0) (41 . 0.0) (42 . 0.0) (91 . 0) (10 402.075 6001.62) (40 . 0.0) (41 . 0.0) (42 . 0.0) (91 . 0) [b][color="#0000ff"](10 -1632.64 5446.11)[/color][/b] (40 . 0.0) (41 . 0.0) (42 . 0.0) (91 . 0) (210 0.0 0.0 1.0)) Quote
alanjt Posted April 16, 2010 Posted April 16, 2010 But if ((-1 . <Имя объекта: 7edf4508>) (0 . "LWPOLYLINE") (330 . <Имя объекта: 7ed49cf8>) (5 . "6369") (100 . "AcDbEntity") (67 . 0) (410 . "Model") (8 . "0") (100 . "AcDbPolyline") (90 . 5) [b][color=Red](70 . 0)[/color][/b] (43 . 0.0) (38 . 0.0) (39 . 0.0) [color=Blue][b](10 -1632.64 5446.11)[/b][/color] (40 . 0.0) (41 . 0.0) (42 . 0.0) (91 . 0) (10 -330.423 2953.1) (40 . 0.0) (41 . 0.0) (42 . 0.0) (91 . 0) (10 3128.59 4700.92) (40 . 0.0) (41 . 0.0) (42 . 0.0) (91 . 0) (10 402.075 6001.62) (40 . 0.0) (41 . 0.0) (42 . 0.0) (91 . 0) [b][color=#0000ff](10 -1632.64 5446.11)[/color][/b] (40 . 0.0) (41 . 0.0) (42 . 0.0) (91 . 0) (210 0.0 0.0 1.0)) True, but it's still not officially closed. However, you could easily revise the code to make sure closed or (equal startpoint endpoint). Quote
alanjt Posted April 16, 2010 Posted April 16, 2010 Ahh, what the hell... (defun c:Test (/ ss h) (vl-load-com) (if (setq ss (ssget '((0 . "LWPOLYLINE") (-4 . "<OR") (70 . 1) (70 . 129) (-4 . "OR>")))) ((lambda (space) (vlax-for x (setq ss (vla-get-activeselectionset *AcadDoc*)) (vla-put-layer (setq h (vla-AddHatch space acHatchPatternTypePredefined "SOLID" :vlax-true)) (vla-get-layer x) ) (vlax-invoke h 'AppendOuterLoop (list x)) (vlax-invoke h 'Evaluate) ) (vla-delete ss) ) (if (or (eq acmodelspace (vla-get-activespace (cond (*AcadDoc*) ((setq *AcadDoc* (vla-get-activedocument (vlax-get-acad-object)))) ) ) ) (eq :vlax-true (vla-get-mspace *AcadDoc*)) ) (vla-get-modelspace *AcadDoc*) (vla-get-paperspace *AcadDoc*) ) ) ) (princ) ) Quote
alanjt Posted April 16, 2010 Posted April 16, 2010 Slightly modified to accept open LWPolylines that have the same Start & End points... (defun c:Test (/ ss h) (vl-load-com) (if (setq ss (ssget '((0 . "LWPOLYLINE")))) ((lambda (space) (vlax-for x (setq ss (vla-get-activeselectionset *AcadDoc*)) (if (or (vlax-curve-isClosed x) (equal (vlax-curve-getStartPoint x) (vlax-curve-getEndPoint x)) ) (progn (vla-put-layer (setq h (vla-AddHatch space acHatchPatternTypePredefined "SOLID" :vlax-true)) (vla-get-layer x) ) (vlax-invoke h 'AppendOuterLoop (list x)) (vlax-invoke h 'Evaluate) ) ) ) (vla-delete ss) ) (if (or (eq acmodelspace (vla-get-activespace (cond (*AcadDoc*) ((setq *AcadDoc* (vla-get-activedocument (vlax-get-acad-object)))) ) ) ) (eq :vlax-true (vla-get-mspace *AcadDoc*)) ) (vla-get-modelspace *AcadDoc*) (vla-get-paperspace *AcadDoc*) ) ) ) (princ) ) Quote
asos2000 Posted January 23, 2011 Posted January 23, 2011 Is there a way to create a hatch by selecting internal point? Quote
Tharwat Posted January 23, 2011 Posted January 23, 2011 Is there a way to create a hatch by selecting internal point? Check this out . (while (setq pt (getpoint "\n Internal Point :")) (command "_.-hatch" pt "_p" "SOLID" "" "") ) Tharwat Quote
asos2000 Posted January 23, 2011 Posted January 23, 2011 Check this out .... Tharwat Thanks for your reply I want to use ADDHATCH Quote
Lee Mac Posted January 23, 2011 Posted January 23, 2011 Is there a way to create a hatch by selecting internal point? I want to use ADDHATCH To accomplish this task using the ActiveX AddHatch method you require a bounding object forming a closed boundary so that you can append the outer loop of the Hatch object (using the AppendOuterLoop method). To obtain such an object using a single point requires a function to test whether a point lies inside an object. This is a classical problem (PIP) can be achieved in various ways, the most common being either Ray-casting or by calculating the Winding Number of the object. The simplest method is to use the Express Tools' function acet-geom-point-inside, although this does create a dependence on the availability of Express Tools on the user's system. With a function to detect whether a point lies inside a polygon, one can check each closed polygon in the drawing and collect those for which the specified point lies inside. From this set we can retrieve the polygon closest to the point and hatch it accordingly. As an example, consider the following code: (defun c:test ( / PointInside ss pt i e l hObj ) (vl-load-com) (defun PointInside ( pt ptlst ) (acet-geom-point-inside pt ptlst ( (lambda ( m / d ) (foreach x ptlst (if (< m (setq d (distance pt x))) (setq m d))) m) 0.0 ) ) ) (if (and (setq ss (ssget "_X" '((0 . "LWPOLYLINE") (70 . 1)))) (setq pt (getpoint "\nPick Internal Point: ")) ) (progn (setq i -1 pt (trans pt 1 0)) (while (setq e (ssname ss (setq i (1+ i)))) (if (PointInside pt (mapcar (function (lambda ( p ) (trans (cdr p) e 0)) ) (vl-remove-if-not (function (lambda ( p ) (= 10 (car p)))) (entget e)) ) ) (setq l (cons e l)) ) ) (if (setq e (car (vl-sort l (function (lambda ( a b ) (< (distance pt (vlax-curve-getClosestPointto a pt)) (distance pt (vlax-curve-getClosestPointto b pt)) ) ) ) ) ) ) (progn (setq hObj (vla-AddHatch (vlax-get-property (vla-get-ActiveDocument (vlax-get-acad-object)) (if (= 1 (getvar 'CVPORT)) 'Paperspace 'Modelspace ) ) acHatchPatternTypePredefined "ANSI31" :vlax-true AcHatchObject ) ) (vlax-invoke hObj 'AppendOuterLoop (list (vlax-ename->vla-object e))) (vla-Evaluate hObj) ) ) ) ) (princ) ) Lee Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.