Jump to content

Recommended Posts

Posted

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.

Vor_Color.JPG

Posted

Is each perimeter made up of a single polyline?

Posted (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 by ronjonp
Posted (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 by GLAVCVS
Posted (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 by GLAVCVS

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...