Snap polyline vertex to the nearest COGO point

Snap polyline vertex to the nearest COGO point

lzedCB
Advocate Advocate
2,442 Views
15 Replies
Message 1 of 16

Snap polyline vertex to the nearest COGO point

lzedCB
Advocate
Advocate

Hello!

 

Any brillant mind knows how to do a LISP that snaps polylines vertices (keeping them at elevation = 0) to the neareast/closest COGO point, but only for COGO points that has layer state "ON" and "not freeze" being shown on screen, then joins all polylines that are snapped to the same point but that are not continous/joined polyline?

 

This video shows a example of the proccess, but imagine having like hundreds of points and polylines to fix their snapping:

 

(view in My Videos)

 

So it would be like a LISP where you make a cross window around the polylines and COGO points you want to snap them, so it will "fix" snap them automatically? Is it possible? Thanks in advance!

0 Likes
Accepted solutions (1)
2,443 Views
15 Replies
Replies (15)
Message 2 of 16

Sea-Haven
Mentor
Mentor

First question why is line work not snapping to correct point ? Are you using say CIV3D and importing points ? It should create lines correctly, or some other spaghetti solution of importing points and lines.

 

Re spaghetti, if you do line connections incorrectly you end up with spaghetti.

 

Yes can take a COGO point and draw a little box around it then using a ssget method to look for objects near to it. If single p/line then easy gets complicated when a point is near a segment of a pline.

0 Likes
Message 3 of 16

lzedCB
Advocate
Advocate

Cable lines Sometimes are targeted separated from "pole" symbols. So, you don't get exactly same spot for both, but they should be represented trought the center of symbol. It's very specific, but it happens...

0 Likes
Message 4 of 16

john.uhden
Mentor
Mentor

@lzedCB ,

I think it can be done, but not totally automatically.  The user has to initiate some command to make it run, as I would prefer it not to have to use a reactor.  Besides, an object that fires a reactor can not be a subject of a reaction.

In fact it could process the whole drawing at once but should have some built-in limitations like certain layers or pairs thereof (point and polyline), and maximum distance to adjust a vertex.  If a vertex is beyond the maximum distance, but the polyline goes right past a point, then do you want to add a vertex?

BTW, what does "V" stand for?  Oh, I see it's actually a check mark.  That could be anything.

John F. Uhden

0 Likes
Message 5 of 16

Sea-Haven
Mentor
Mentor

Just a comment I did something like this for a client DWG, changing say 500 items takes a couple of seconds. 

 

Do you know anything about lisp ?

0 Likes
Message 6 of 16

lzedCB
Advocate
Advocate
Hy friend! I have no clue about LISP. Anyways, I was thinking it was "easier" task or LISP. I'm thankful for your toughts on this.
0 Likes
Message 7 of 16

Sea-Haven
Mentor
Mentor

Before any one can help you need a sample dwg. Need to know block names etc.

0 Likes
Message 8 of 16

lzedCB
Advocate
Advocate

Here is an example file! Thnks in advance.

0 Likes
Message 9 of 16

ВeekeeCZ
Consultant
Consultant
Accepted solution

Possibly something like this.

No layer filtering or anything. Just select the plines with cogos and if there some point within the given distance from some vertex, it will fix the coords. 

 

(vl-load-com)

(defun c:SnapPlines2CogoFuzz nil

  (or (and *SPL2C-fuzz* (numberp *SPL2C-fuzz*))
      (setq *SPL2C-fuzz* 1))
  (setq *SPL2C-fuzz* (cond ((getdist (strcat "\nSpecify value of fuzzy <" (rtos *SPL2C-fuzz*) ">: "))) (*SPL2C-fuzz*))))


(defun c:SnapPlines2Cogo ( / s l i e d) 
  
  (if (and (setq s (ssget  '((0 . "AECC_COGO_POINT,LWPOLYLINE"))))
	   (setq l (ssget "_P" '((0 . "AECC_COGO_POINT"))))
	   (setq l (vl-remove-if 'listp (mapcar 'cadr (ssnamex l))))
	   (setq l (mapcar '(lambda (x) (vlax-get (vlax-ename->vla-object x) 'Location)) l))
	   (setq l (mapcar '(lambda (x) (reverse (cdr (reverse x)))) l))
	   (or *SPL2C-fuzz* (c:SnapPlines2CogoFuzz))
	   )
    (repeat (setq i (sslength s))
      (setq e (ssname s (setq i (1- i)))
	    d (entget e))
      (if (= "LWPOLYLINE" (cdr (assoc 0 d)))
	(entmod (mapcar '(lambda (x / p)
			   (if (= (car x) 10)
			     (progn
			       (setq p (cdr x))
			       (setq l (vl-sort l '(lambda (x1 x2) (< (distance p x1) (distance p x2)))))
			       (cons 10 (if (< (distance (car l) p) *SPL2C-fuzz*)
					  (car l) p))) 			
			     x))
			d)))))
  (princ)
  )

 

0 Likes
Message 10 of 16

komondormrex
Mentor
Mentor

is that written for autocad? since it is autocad topic.

0 Likes
Message 11 of 16

ВeekeeCZ
Consultant
Consultant

No. The OP has C3D.

0 Likes
Message 12 of 16

lzedCB
Advocate
Advocate

Thanks @ВeekeeCZ. This is more than enough and works together with Isolate and Unisolated command, so it's not necessary any filter as it can be easily Isolated just the polylines and points of interest before applying this LISP! Would be perfect with the fuzz distance could be specified while running the LISP.

 

Thanks for sharing with us such a brillant mind!

0 Likes
Message 13 of 16

ВeekeeCZ
Consultant
Consultant

Code updated.

Set it for the first time. Then change it by SnapPlines2CogoFuzz.

0 Likes
Message 14 of 16

lzedCB
Advocate
Advocate

@ВeekeeCZ Thanks! It worked perfectly here. 🤗

0 Likes
Message 15 of 16

kmohs
Contributor
Contributor
Would it be possible to modify the routine to accommodate feature lines and elevation data?
0 Likes
Message 16 of 16

Sea-Haven
Mentor
Mentor

It may be better to start a new post and provide more visual information like images or best a dwg.

0 Likes