Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Hatch merge/split,

24 REPLIES 24
SOLVED
Reply
Message 1 of 25
JamaL9722060
22876 Views, 24 Replies

Hatch merge/split,

Hatch merge/split,

 

I got a lisp file that does merge two existing hatching into one.

 

  • But the issue is that in case of overlapping hatches the code does merge the hatches BUT it subtracts the overlapping area of the two hatches!

What I wanted is to merge them and to keep the overlapping area as a part of the result

 

  • I couldn’t find any lisp file that split an existing hatch based on multiple existing lines

 

 

Thank you

 

Best

 

Jamal

---------------------------
Jamal Numan
24 REPLIES 24
Message 2 of 25
devitg
in reply to: JamaL9722060

Would you , please  upload , or send it off line, a sample DWG with such hatches

Message 3 of 25
JamaL9722060
in reply to: devitg

Many thanks devitg for the help,

 

In the attached screenshots (and also the dwg file)

 

  1. I wanted to merge the overlapping hatches (indicated on the screenshot)

 

  1. I wanted to split the hatch based on an existing line(indicated on the screenshot)

 

Best

 

Jamal

---------------------------
Jamal Numan
Message 4 of 25
JamaL9722060
in reply to: devitg

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

---------------------------
Jamal Numan
Message 5 of 25
Kent1Cooper
in reply to: JamaL9722060


@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.

Kent Cooper, AIA
Message 6 of 25
JamaL9722060
in reply to: Kent1Cooper

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!

 

http://forums.autodesk.com/t5/Visual-LISP-AutoLISP-and-General/Merging-hatches-that-have-gabs-and-or...

 

Best

 

Jamal

---------------------------
Jamal Numan
Message 7 of 25
hmsilva
in reply to: JamaL9722060

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

EESignature

Message 8 of 25
JamaL9722060
in reply to: hmsilva

 

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

 

---------------------------
Jamal Numan
Message 9 of 25
hmsilva
in reply to: JamaL9722060

Jamal,
as I wrote in my previous post, "will merge overlapping hatches"..
In your example the seven hatches are forming two distinct zones, and both zones are coincident only in one point, so it is impossible to define an common area to the two hatch zones, would be require at least two common points, or an overlap area, for the resulting boundary be only one.

Henrique

EESignature

Message 10 of 25
JamaL9722060
in reply to: hmsilva

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

---------------------------
Jamal Numan
Message 11 of 25
hmsilva
in reply to: JamaL9722060

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

EESignature

Message 12 of 25
JamaL9722060
in reply to: hmsilva

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

---------------------------
Jamal Numan
Message 13 of 25
hmsilva
in reply to: JamaL9722060

You're welcome, Jamal

Cheers
Henrique

EESignature

Message 14 of 25
JamaL9722060
in reply to: hmsilva

Hi Henrique,

 

How about a lisp file that can split an existing hatch?

 

Best

 

Jamal

---------------------------
Jamal Numan
Message 15 of 25
hmsilva
in reply to: JamaL9722060

Hi Jamal,
I never done anything to split an existing hatch, but let's see if I can think in a way to do it...

Cheers
Henrique

EESignature

Message 16 of 25
JamaL9722060
in reply to: hmsilva

Thanks Henrique

Best

 

Jamal

---------------------------
Jamal Numan
Message 17 of 25
hmsilva
in reply to: JamaL9722060

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

EESignature

Message 18 of 25
JamaL9722060
in reply to: hmsilva

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 Numan
Message 19 of 25
hmsilva
in reply to: JamaL9722060

Jamal,

the code I posted, had a extra bracket...

Try the attached one.

 

Henrique

EESignature

Message 20 of 25
JamaL9722060
in reply to: hmsilva

Many thanks Henrique for the effort. It works fine.

 

Very much appreciated

 

Best

 

Jamal

---------------------------
Jamal Numan

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost