Hatch merge/split,
I got a lisp file that does merge two existing hatching into one.
What I wanted is to merge them and to keep the overlapping area as a part of the result
Thank you
Best
Jamal
Solved! Go to Solution.
Solved by hmsilva. Go to Solution.
Would you , please upload , or send it off line, a sample DWG with such hatches
Many thanks devitg for the help,
In the attached screenshots (and also the dwg file)
Best
Jamal
I’m attaching another example in which the hatches are erased as the lisp command “merge hatch” is applied
What might be the issue here?
The dwg file and lisp file are attached
Best
Jamal
@JamaL9722060 wrote:I’m attaching another example in which the hatches are erased as the lisp command “merge hatch” is applied
What might be the issue here?
....
Hatch entity data is extraordinarily complicated, so it's hard even to analyze where everything is coming from, much less how to put it together from several patterns into one, but one thing I noticed:
A Hatch pattern made by either selecting internal points or closed objects will have a DXF code 91 value, or a NumberOfLoops VLA property, equal to the number of boundaries. The long skinny through-the-middle Hatch in your sample drawing was made from 7 boundaries, and the remaining three were made from single boundaries. That suggests to me that the overall merged pattern should have a DXF 91/NumberOfLoops value of 7 + 1 + 1 + 1 = 10. But it looks like the code assigns a value equal to the number of patterns selected to merge, which would be 4 in this case.
When I drew two Hatch patterns, each involving a single defining boundary, MergeHatch worked, which suggested to me that maybe that DXF 91/NumberOfLoops element could be the issue. But when I tried merging the three Hatches in your drawing that have single defining boundaries, omitting the one with 7, they were all deleted just as when that 7-loop one was included, so apparently that is not all of the problem.
Many thanks Kent for the very useful elaboration,
Then a lisp file that can do which is described in the next link sounds to be impossible!
Best
Jamal
Jamal,
I've done a code to merge hatches, it was made a few years ago, the problem is, I can't find it!!!
So, I wrote this code, on the fly, it will merge overlapping hatches, it is not a fast code, because it uses multiple commands, but works.
Try it, is minimally tested...
(defun c:test (/ ss zer ss1 hpb olde itm ent bou ss2) (alert "\n Select hatch to Merge.\n\nFirst one will be the Properties Source." ) (if (setq ss (ssget ":L" '((0 . "HATCH")))) (progn (command "_.undo" "_BE") (setq olde (getvar 'cmdecho) hpb (getvar 'hpbound) itm -1 ss1 (ssadd) zer (entlast) ) (ssadd zer ss1) (setvar 'hpbound 0) (setvar 'cmdecho 0) (while (setq ent (ssname ss (setq itm (1+ itm)))) (command ".-hatchedit" ent "b" "r" "y") );; while (while (setq zer (entnext zer)) (ssadd zer ss1) );; while (ssdel (ssname ss1 0) ss1) (command "_.union" ss1 "") (setq bou (entlast)) (command "_.hatch" "solid" "l" "") (setq ss2 (ssget "_L")) (command "_.copy" (ssname ss 0) "" "0,0,0" "0,0,0" "_.erase" "p" "" "_.matchprop" "L" ss2 "" "_.draworder" ss2 "" "b" "_.erase" "L" bou ss "" ) );; progn );; if (command "_.undo" "_E") (setvar 'hpbound hpb) (setvar 'cmdecho olde) (princ) );; test
hope that helps
Henrique
Very much appreciated Henrique for the help,
The lisp file that you have generously shared is great but still includes unexpected behavior
In the attached dwg file I got 7 hatches that I wanted to merge and then to draw a boundary for them (using another lisp file (attached).
The result is attached. Two boundaries are created! While it is assumed to be one as the hatches are assumed to merged to be one.
What is the issue then?
Best
Jamal
Very much appreciated Henrique for the elaboration,
I got your point. Now it is clearer how the lisp works.
My idea was concerning the possibility to create hatch if the gab between selected hatches (that are aimed to be merged) is within a particular tolerance.
For example, in the attached screenshot, I’m dreaming to have a lips file that merges selected hatches in that manner (to create hatches where the gab is less than the tolerance)
Best
Jamal
Hi Jamal,
I understand your idea, but it would not be easy to create a tool that would merge hatches with a gap between them, mainly because to ensure that the final boundary would be desired, it would be almost impossible,
Jamal, in the example you attached, it would be possible to create a code to find a vertex coincident to both boundaries, and the two nearest points from the both boundaries, and then generate a new boundary, but your example is not the general case, many times, hatch boundaries may have very different shapes, and in that case it would be very difficult to create a tool that was reliable for all situations...
See the example I have attached, I think that exemplifies what I tried to say.
Cheers
Henrique
Many thanks Henrique for the prompt help and the elaboration
I do agree
The lisp file you have provided is fantastic and does do the job
Best
Jamal
Hi Henrique,
How about a lisp file that can split an existing hatch?
Best
Jamal
Jamal,
as I said:
"I never done anything to split an existing hatch, but let's see if I can think in a way to do it..."
This is how I can split an existing hatch, this code is not bullet-proof, is only a demo, and was made to try to demonstrate a way to get the hatch split...
Try it, is minimally tested...
(defun c:test (/ c e hpb itm olde p pts selp ss ss1 ss2 ss3) (prompt "\nSelect the lines to split hatch: ") (if (setq ss (ssget ":L" '((0 . "LINE,LWPOLYLINE,ARC")))) (progn (prompt "\nSelect the hatch to split: ") (if (setq ss1 (ssget ":S:L" '((0 . "HATCH")))) (progn (command "_.undo" "_BE" "_ucs" "_W" "_plan" "") (setq olde (getvar 'cmdecho) hpb (getvar 'hpbound) selp (getvar 'selectionpreview) itm -1 fuzz 0.25) (command ".-hatchedit" (ssname ss1 0) "_b" "_r" "_y" "._extrude" "_L" "" "5") (while (setq e (ssname ss (setq itm (1+ itm)))) (command "._imprint" "_L" e "n" "") (setq c (vlax-ename->vla-object e) p (vlax-curve-getpointatdist c (/ (vlax-curve-getdistatparam c (vlax-curve-getendparam c)) 2. ) ) pts (cons p pts) p (polar p (* pi 0.25) fuzz) pts (cons p pts) p (polar p (* pi 1.25) fuzz) pts (cons p pts) )) );; while (command "._explode" "_L" "") (setq ss2 (ssget "_P") ss3 (ssget "_F" pts '((0 . "REGION")))) (command "._erase" ss2 "_R" ss3 "") (setq itm -1) (while (setq e (ssname ss3 (setq itm (1+ itm)))) (command "_.hatch" "solid" e "" "_.matchprop" ss1 "_L" "" "_.draworder" "_L" "" "_B") );; while (command "erase" ss1 ss3 "") );; progn );; if );; progn );; if (setvar 'hpbound hpb) (setvar 'selectionpreview selp) (setvar 'cmdecho old) (command "_ucs" "_P" "_zoom" "_P" "_.undo" "_E") (princ) );; test
hope that helps
Henrique
Many thanks Henrique!
Sounds not to work. It is added to the “load application” but doesn’t appear on the commands list (attached)
What might be the issue?
Jamal,
the code I posted, had a extra bracket...
Try the attached one.
Henrique
Many thanks Henrique for the effort. It works fine.
Very much appreciated
Best
Jamal