nedko9404 Posted Monday at 01:48 PM Posted Monday at 01:48 PM Hello, I am a mining engineer and my task is to calculate the reserves of raw materials in the earth's bowels. The calculation method is with the so-called centroids. I found a Lisp that will help me automatically draw closed polygons (Polyline) around the drilling holes (using the Voronoi method. In the center of each closed polygon there is a point (Drilling) (AutoCAD Point) with a certain color. I am looking for a Lisp that will make Hatch in all closed polygons based on the color of the point that is located in the center of each of them. Quote
GLAVCVS Posted Monday at 06:51 PM Posted Monday at 06:51 PM Is each perimeter made up of a single polyline? Quote
ronjonp Posted Monday at 07:56 PM Posted Monday at 07:56 PM (edited) @nedko9404 Welcome to CadTutor! Here's a start .. a sample drawing would help: (defun c:foo (/ _addhatch _boundary b spc s) (defun _addhatch (spc bnd lyr / h) (if (setq h (vlax-invoke spc 'addhatch achatchobject "Solid" :vlax-true)) (progn (vlax-invoke h 'appendouterloop (list bnd)) (vla-put-layer h lyr) (vla-evaluate h) (vla-update h) h ) ) ) (defun _boundary (p / e) (setq e (entlast)) (bpoly p) (if (not (equal e (entlast))) (entlast) ) ) (cond ((setq s (ssget '((0 . "POINT")))) (setq spc (vlax-ename->vla-object (cdr (assoc 330 (entget (ssname s 0)))))) (setvar 'cmdecho 0) (command "_.undo" "_begin") (foreach e (vl-remove-if 'listp (mapcar 'cadr (ssnamex s))) (if (setq b (_boundary (cdr (assoc 10 (entget e))))) (progn (_addhatch spc (vlax-ename->vla-object b) (cdr (assoc 8 (entget e)))) (entdel b)) ) ) (command "_.undo" "_end") (setvar 'cmdecho 1) ) ) (princ) ) Edited Monday at 08:32 PM by ronjonp Quote
GLAVCVS Posted Monday at 08:46 PM Posted Monday at 08:46 PM (edited) On 2/3/2025 at 6:51 PM, GLAVCVS said: Is each perimeter made up of a single polyline? Well. I guess it doesn't matter. I said this because the 'boundary' command or its analogue 'bpoly' suffer when the drawing is complex. Here is another one that might be useful to you. (defun c:creaSombrs (/ conj ent lstent n pto entUlt entUlt1) (setq n 0 entUlt (entlast) ) (princ "\nSelect points centroids... ") (if (setq conj (ssget '((0 . "POINT") (8 . "*")))) (while (setq ent (ssname conj n)) (bpoly (setq pto (cdr (assoc 10 (setq lstent (entget ent)))))) (if (NOT (equal (setq entUlt1 (entlast)) entUlt)) (progn (vl-cmdf "_hatch" "SOLID" entUlt1 "") (if (not (equal (entlast) entUlt1)) (vlax-put-property (vlax-ename->vla-object (entlast)) "Color" (cdr (assoc 62 lstent)) ) ) ) (princ (strcat "\n*** No fue posible definir perimetro de sombreado para punto de coordenada " (rtos (car pto) 2 2) " , " (rtos (cadr pto) 2 2) ) ) ) (setq n (1+ n)) ) ) (princ) ) Edited yesterday at 12:34 AM by GLAVCVS Quote
GLAVCVS Posted Monday at 08:58 PM Posted Monday at 08:58 PM (edited) Of course: you will have to change, in the code, "SOLID" with the name of any other hatch pattern you want to use. And if you want it to only select the points of a specific layer, change the '*' that appears in '...(8 . "*")' to the name of the desired layer, '(8 . " NameLayer1")', for example Edited Monday at 09:47 PM by GLAVCVS Quote
mhupp Posted Monday at 10:40 PM Posted Monday at 10:40 PM Here is another way if they are just lines 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.