PDA

View Full Version : Remove inner boundaries/vertices of a hatch



mattko
2016-06-27, 01:38 PM
Hi,
is there a way, or a lisp, that can remove inner boundaries/vertices of a hatch? In other words, simplifying a hatch.
Like in the attached image.

mattko
2016-06-27, 01:45 PM
Also, what do these plus signs mean near some of the vertices?

mattko
2016-06-27, 03:20 PM
Ok, I found a way to do that, and I hope somebody would be so kind and make a lisp to speed up the procedure :beer:
I tried to do it myself, but found a problem.

1. Generate a boundary along all hatch vertices (command HATCHGENERATEBOUNDARY)
2. Select all generated polylines (this is where I'm stuck, how do I make a selection set of these polylines, and only these polylines?)
3. Convert these polylines to regions
4. Select these regions (similar problem to step #2), then use the UNION command to merge the regions
5. Hatch the unified region

Opie
2016-06-27, 03:39 PM
To answer your question for step 2, create a variable of the last entity in the drawing prior to generating the boundaries in step 1. Once you have generated the boundaries, you can cycle through the newly created entities in the drawing using the entnext function. Of course, you will want to add each one of those new entities into a selection set using the ssadd function. This will allow you to convert those polylines to regions in step 3.

mattko
2016-06-27, 04:03 PM
Yep, that did it, thanks :)

Here's the code:


(defun c:hatchsimplify (/)

(prompt "\nChoose hatch entity: ")
(setq hec0 (car (entsel)))

(setq lastEnt (entlast))

(command "HATCHGENERATEBOUNDARY" hec0 "")

(setq hecplinije (ssadd))
(while (setq lastEnt (entnext lastEnt))
(ssadd lastEnt hecplinije)
)
(sssetfirst nil hecplinije)


(setq lastEnt (entlast))

(command "region" hecplinije "")

(setq hecregije (ssadd))
(while (setq lastEnt (entnext lastEnt))
(ssadd lastEnt hecregije)
)
(sssetfirst nil hecregije)


(command "union" hecregije "")
(setq unreg (entlast))

(command "-hatch" "s" unreg "" "")
(setq hec1 (entlast))

(command "matchprop" hec0 hec1 "")

(entdel hec0)
(entdel unreg)


(princ)
)

3dwannab
2024-11-09, 04:16 PM
Yep, that did it, thanks :)

Here's the code:

I've modified this to:

- Add a selection of multiple NON-associative hatches instead of associative ones also.
- Fix localising of the variables.
- Have better undo handling.




;|

Simplify hatches. This is when the hatch is intersecting with itself.

3dwannab modification of code found here: https://forums.augi.com/showthread.php?166621-Remove-inner-boundaries-vertices-of-a-hatch&p=1315048&viewfull=1#post1315048

3dwannb edit 2024.11.09
- Add a selection of multiple NON-associative hatches instead of associative ones also.
- Fix localising of the variables.
- Have better undo handling.

|;

(defun c:FXHatch_Simplify (/ *error* acDoc hec01 hecplinije hecregije lastEnt unreg acDoc var_cmdecho i ent newHatches var_cmdecho)

(defun *error* (errmsg)
(and acDoc (vla-EndUndoMark acDoc))
(and errmsg
(not (wcmatch (strcase errmsg) "*CANCEL*,*EXIT*"))
(princ (strcat "\n<< Error: " errmsg " >>\n"))
)
(setvar 'cmdecho var_cmdecho)
)

;; Start the undo mark here
(setq acDoc (vla-get-ActiveDocument (vlax-get-acad-object)))
(or (vla-EndUndoMark acDoc) (vla-StartUndoMark acDoc))

;; Get any system variables here
(setq var_cmdecho (getvar "cmdecho"))

(setvar 'cmdecho 0)

;; Create a selection set for any non associative hatches
(setq hec01 (ssget "_:L" '((0 . "HATCH") (-4 . "=") (71 . 0))))

(if hec01
(progn
;; Initialize a selection set for new hatches
(setq newHatches (ssadd))

;; Iterate over each entity in the selection set
(repeat (setq i (sslength hec01))
(setq ent (ssname hec01 (setq i (1- i))))

;; Process the current entity
(setq lastEnt (entlast))

(command "HATCHGENERATEBOUNDARY" ent "")

;; Collect boundary entities
(setq hecplinije (ssadd))
(while (setq lastEnt (entnext lastEnt))
(ssadd lastEnt hecplinije)
)
(setq lastEnt (entlast))

;; Create regions from the boundaries
(command "region" hecplinije "")

;; Collect region entities
(setq hecregije (ssadd))
(while (setq lastEnt (entnext lastEnt))
(ssadd lastEnt hecregije)
)

(command "union" hecregije "")
(setq unreg (entlast))

;; Create a new hatch based on the union region
(command "-hatch" "s" unreg "" "")
(setq hec1 (entlast))

;; Add the new hatch to the selection set for later use
(ssadd hec1 newHatches)

;; Match properties and clean up
(command "matchprop" ent hec1 "")

(entdel ent)
(entdel unreg)
)

;; Highlight the new hatches
(if newHatches
(progn
(sssetfirst nil newHatches)
(princ (strcat "\n" (itoa (sslength newHatches)) (if (> (sslength newHatches) 1) " hatches" " hatch") " simplified."))
)
(prompt "\nNo hatch entities found.")
)
)
)

(vla-EndUndoMark acDoc)

(*error* nil)
(princ)
)

; (c:FXHatch_Simplify) ;; Unblock for testing