FIND OVERLAPPING POLYLINE AND DELETE BOTH

FIND OVERLAPPING POLYLINE AND DELETE BOTH

paliwal222
Advocate Advocate
3,542 Views
13 Replies
Message 1 of 14

FIND OVERLAPPING POLYLINE AND DELETE BOTH

paliwal222
Advocate
Advocate

WANT TO SELECT ALL OVER LAPPING POLYLINES, 

LAYER,COLOR OR GLOBAL WIDTH, SAME OR DIFFERENT IS NOT MATTER, 

WANT TO ERASE BOTH OVERLAPPED OBJECT.

(THOUGH I HAVE BREAKED POLYLINES AT OVERLAPPING POINT ALREADY)

0 Likes
3,543 Views
13 Replies
Replies (13)
Message 2 of 14

hak_vz
Advisor
Advisor

Since you polylines are already breaked, use command Overkill to remove all duplicate objects.

overkill_box.jpg

 Plines from under will be removed. and you just have to erase previously overlapping polylines. You should have them in some separate layer, or created with some specific (unique) color.

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
Message 3 of 14

paliwal222
Advocate
Advocate
but its only delete duplicate (i have to delete all overlapping object and "base object" also.)
0 Likes
Message 4 of 14

hak_vz
Advisor
Advisor

@paliwal222 wrote:
but its only delete duplicate (i have to delete all overlapping object and "base object" also.)

Overkill will delete "base object" i.e. polyline in back. Then select remainder to delete. Sorry, but you have to use layers and not mix all entities into same drawing.

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
Message 5 of 14

hak_vz
Advisor
Advisor

If you are lucky and remaining segments that are not intended to be erased have more than 2 segments (i.e. number of vertexes is greater than 2) than simple selection may work.

(setq ss (ssget '((0 . "LWPOLYLINE")(90 . 2))))

You can than use ERASE or MOVE

Command: ERASE
Select objects: !ss .....

 

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
Message 6 of 14

paliwal222
Advocate
Advocate

Sir, but some time overkill behaviour is strange but, i will try by on/off the given  option in ovrtkill window.

0 Likes
Message 7 of 14

paliwal222
Advocate
Advocate

OK, it's work on "0" tolerance.

Message 8 of 14

paliwal222
Advocate
Advocate

Dears

sorry, its still unsolved, I am unable to select "base object"

above method is delete only overlapped object, not "base object".

I have 2 drawing of centrelines  first is old, second is continue with old 

with new centrelines  with "joining some old polyline"

I braked the overlapping ends, and give overkill, but its delete only overlapped object not base object.

0 Likes
Message 9 of 14

hak_vz
Advisor
Advisor

First thing first. Separate your overlap objects to different layer.Its hard to work when everything is in same layer. Idea.

Select all overlap object and find similar in other based on geometry.  Also try with selection sets.

The way have it created in your drawing is not usable to create some code.

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
Message 10 of 14

hak_vz
Advisor
Advisor

@paliwal222 wrote:

WANT TO SELECT ALL OVER LAPPING POLYLINES, 

LAYER,COLOR OR GLOBAL WIDTH, SAME OR DIFFERENT IS NOT MATTER, 

WANT TO ERASE BOTH OVERLAPPED OBJECT.

THOUGH I HAVE BREAKED POLYLINES AT OVERLAPPING POINT ALREADY


For your particular case, where all entities are polylines, and overlaps are singe segment polylines (only two points) this will erase all overlapping elements and polylines laying under.

It is important that startpoint and endpoint of overlapping elements coincide. Direction how they are created and other features like layer, color etc. are  not considered.

You should break polylines as you stated above.

 

 

(defun c:delete_overlap (/ *error* adoc collinear ss i a e eo mm to_delete)
	;Author:  hak_vz 
	;Thursday, September 30, 2021
	;https://forums.autodesk.com/t5/user/viewprofilepage/user-id/5530556
	;Posted at 
	;https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/find-overlapping-polyline-and-delete-both/td-p/10649230
	;Erases overlaped polyline segment (2 vertex poly) and polyline under it
	(defun *error* ( msg )
		(if (not (member msg '("Function cancelled" "quit / exit abort")))
			(princ)
		)
		(if (and adoc) (vla-endundomark adoc))
		(princ)
	)
	(defun collinear (p1 p2 p3 / a b c d)(setq a (angle p1 p2) b (angle p1 p3) c (angle p3 p1) d (angle p3 p2))(or (= a b)(= a c) (= a d) (= b a) (= b c) (= b d)))
	(setq adoc (vla-get-ActiveDocument (vlax-get-acad-object)) blocks (vla-get-blocks adoc))
	(vla-endundomark adoc)
	(vla-startundomark adoc)
	(setq ss (ssget '((0 . "LWPOLYLINE")(-4 . "=")(90 . 2))))
	(setq i -1)
	(while (< (setq i (1+ i)) (sslength ss))
	(setq e (ssname ss i) eo (vlax-ename->vla-object e))
	(setq mm (cons (list (vlax-Curve-getStartPoint eo)(vlax-Curve-getEndPoint eo) e) mm))
	)
	(while (and mm (>= (length mm) 2))
		(setq a (car mm) mm (cdr mm))
		(setq p1 (car a) p2 (cadr a))
		(foreach e mm
			(setq p3 (car e) p4 (cadr e))
			(cond
				(
					(and
						(<= (abs(- (distance p1 p2)(distance p3 p4))) 1e-8)
						(or
							(or
								(apply 'and (mapcar '= p1 p3))
								(apply 'and (mapcar '= p1 p4))
							)						
							(or
								(apply 'and (mapcar '= p1 p4))
								(apply 'and (mapcar '= p2 p3))
							)
						)
						(collinear p1 p2 p3)
						(collinear p1 p2 p4)
					)
					(setq to_delete (cons (last a) to_delete))
					(setq to_delete (cons (last e) to_delete))
				)

			)
		)
	)
	(foreach e to_delete (entdel e))
	(vla-endundomark adoc)
	(princ)
)

 

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
Message 11 of 14

paliwal222
Advocate
Advocate

Dear,

Sir

I used the lisp but I cant under stand it.

I think that some other way is good, but my task is completed this time.

Thanks very much for all this.

Thanks.

 

0 Likes
Message 12 of 14

paliwal222
Advocate
Advocate

Sir,

when I applied the lisp 1st time its give 100% correct

but when I applied it 2nd time its delete both overlap and base polyline also at approx. 1% of total polylines.

ok.

thanks.

0 Likes
Message 13 of 14

hak_vz
Advisor
Advisor

@paliwal222Run script only once over a set of overlapping polylines and assure that before that all base polylines are braked as in your sample. I didn't lest it for multiple runs over same set of overlapping polylines. As you say in first run it works 100 % ok. Eventual changes through the weekend.

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
Message 14 of 14

hak_vz
Advisor
Advisor

@paliwal222  I've checked the code and it works as expected. In your original request, ass written in sample file you have asked that both overlapping polylines get erased, and code works in that way. What you have to assure is both polylines have equal start and end point i.e. you have to break base polyline at endpoints of overlapping polyline. If you need something else then give me more details and attach more complex sample.

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.