Snapping 2 Polylines on top of each other that are slightly offset!

Snapping 2 Polylines on top of each other that are slightly offset!

timLNMHN
Contributor Contributor
660 Views
9 Replies
Message 1 of 10

Snapping 2 Polylines on top of each other that are slightly offset!

timLNMHN
Contributor
Contributor

Schermafbeelding 2023-12-21 112326.png

As you can see in the screenshot above there is a blue Polyline called 'Accessnet' , this one is connected to all these orange blocks what we call 'ROL'. don't mind the 'ROL' for now.

 

Schermafbeelding 2023-12-21 112338.png

Zooming in further we see that there is also a red Polyline called 'Trench'. The red and blue Polyline should be snapped on top of each other. Preferably that only the red Polyline will shift not the blue Polyline called 'Accessnet'. is there a possibility that the trench can be moved so that it matches the same route as the blue polyline? I was thinking if a lisp could add vertexes on the trench the same as the accessnet that would fix the problem in a automated LISP.

 

 

Schermafbeelding 2023-12-21 112356.png

Now if possible I want the LISP to do the whole drawing at once. The places as you can see that don't have overlapping lines can just stay the way they are. but as soon as the 2 lines are on the same path I would like them to snap on top of each other (if they are not already).

 

Hopefully my request is clear and is there a possibility to find something for this 🙂

 

Thanks in advance

 

Sample drawing added for more clarity

 

   

0 Likes
661 Views
9 Replies
Replies (9)
Message 2 of 10

john.uhden
Mentor
Mentor

@timLNMHN ,

As I see it, the simplest thing to do is just replacing all the coordinates and bulges from the blue into the red one.  But you said multiple, so I guess we have to have a way to determine which red one goes with which blue one... proximity?  variance of path?  divine intervention?

Then again, maybe it doesn't matter as long as there are the same number of reds as blues.

I mean so what if the one from Oregon ends up in NJ and the one from Georgia ends up in Oregon?  I trust we are not concerned with polyline widths, especially varying ones.

John F. Uhden

0 Likes
Message 3 of 10

timLNMHN
Contributor
Contributor

Hello John,

 

I get your point, the problem is that the red polyline doesn't always have a blue one to go on top of it. (this is how our network works). The blue one should not move because it is connected to the mentioned blocks called 'Rol' if that connection isn't there it is going to give us problems in the future. That why if it was possible only the red polyline would shift to the blue polyline. so overall it is a tricky situation and not easy to find a definitive solution. Also because what I am asking doesn't always happen, the red and blue line being together all the time.

 

thanks for your reply 🙂

0 Likes
Message 4 of 10

ВeekeeCZ
Consultant
Consultant

Here is something that might help you identify the issues you need to fix. I am NOT going to do a routine that actually fixes it.

 

This checks the minimum distance of all half-vertex points of selected Trench plines to closest accessnet pline. If it's within the specified range 1e-9 < x < 1e-1 it makes a point there. 

 

You can do all to all check, but it takes some time to process (say about 1 min here on your sample). So better narrow down the selection if your file is too large.

 

(defun c:MidCheck ( / r a c i)

  (if (and (princ "\nSelect Trench polylines to check <all>: ")
	   (setq r (cond ((ssget (list '(0 . "LWPOLYLINE") '(8 . "Trench") (cons 410 (getvar 'ctab)))))
			 ((ssget "_X" (list '(0 . "LWPOLYLINE") '(8 . "Trench") (cons 410 (getvar 'ctab)))))))
	   (setq r (vl-remove-if 'listp (mapcar 'cadr (ssnamex r))))
	   (setq r (mapcar '(lambda (e) (mapcar 'cdr (vl-remove-if '(lambda (x) (/= (car x) 10)) (entget e)))) r))
	   (setq r (mapcar '(lambda (v) (mapcar '(lambda (v1 v2) (mapcar '/ (mapcar '+ v1 v2) '(2 2))) v (cdr v))) r))
	   (setq r (apply 'append r))
	   (princ "\nSelect AccessNet polylines to check <all>: ")
	   (setq a (cond ((ssget (list '(0 . "LWPOLYLINE") '(8 . "AccessNet") (cons 410 (getvar 'ctab)))))
			 ((ssget "_X" (list '(0 . "LWPOLYLINE") '(8 . "AccessNet") (cons 410 (getvar 'ctab)))))))
	   (setq a (vl-remove-if 'listp (mapcar 'cadr (ssnamex a))))
	   (setq i 0)
	   )
    (foreach p r
      (setq c (vl-sort a '(lambda (e1 e2) (< (distance p (vlax-curve-getclosestpointto e1 p)) (distance p (vlax-curve-getclosestpointto e2 p))))))
      (if (< 1e-9 (distance p (vlax-curve-getclosestpointto (car c) p)) 1e-1)
	(progn
	  (entmake (list '(0 . "POINT") (cons 10 p) '(8 . "VERTEXMISSING")))
	  (setq i (1+ i))))))
  (princ "\n") (princ i) (princ " points found.")
  (princ)
  )

 

0 Likes
Message 5 of 10

john.uhden
Mentor
Mentor

@timLNMHN 

Hmm.  so, how currently do you judge if a certain red one goes with a certain blue one or maybe none at all?

John F. Uhden

0 Likes
Message 6 of 10

timLNMHN
Contributor
Contributor

I guess it should be meassured by how far the offset is from each other. so in the example that I showed you it should only be like a few cm. give or take +/- 10 cm or so. so that could be tricky, but could be a possible solution perhaps.

0 Likes
Message 7 of 10

timLNMHN
Contributor
Contributor

Thank you it is working to some extent, I am not that great with numbers but till how many cm's offset will it specifically search? 

0 Likes
Message 8 of 10

john.uhden
Mentor
Mentor

@timLNMHN ,

I think I would build a new proximity function that measures the gaps between two polylines at some interval along their route, with the lowest average gap being the most proximitous.

John F. Uhden

0 Likes
Message 9 of 10

ВeekeeCZ
Consultant
Consultant

@timLNMHN wrote:

Thank you it is working to some extent, I am not that great with numbers but till how many cm's offset will it specifically search? 


 

Well, it's 0.000000001 - 0.1 d.u.

FYI Excel would make you great again if you gave him a chance.

0 Likes
Message 10 of 10

john.uhden
Mentor
Mentor

Hi, @ВeekeeCZ ,

Please explain to this pea brain what - 0.1 d.u. represents.

Okay, I'm gonna guess "drawing units." 

Is that like (equal this that 0.1)?  What's the minus sign for?  Do you need it?

Command: (equal 2.45 2.5 0.1)
T

Command: (equal 2.45 2.5 -0.1)
T

Of course my brother tried to teach me that 1+1=3 for large values of 1.  Then again, he didn't make it to age 50.  Thank God I still have my oldest brother.  He'll be turning 90 next October.

John F. Uhden

0 Likes