Calculating distance to intersection from start of the polylines

Calculating distance to intersection from start of the polylines

Anonymous
Not applicable
1,539 Views
5 Replies
Message 1 of 6

Calculating distance to intersection from start of the polylines

Anonymous
Not applicable

Hello,
I have this little problem which believe can be done with LISP program, but I have no idea how to make it.

I would like to calculate distance from start of each of the selected polylines to the point where other polyline intersects.  Below is example of situation and part of the needed output to excel. The distance should be measured along the polyline's vertexes not the perpendicular (nearest) distance.

eemelilamsijarvi_0-1630302314902.png

eemelilamsijarvi_1-1630302456412.png


Thanks in advance!

0 Likes
Accepted solutions (1)
1,540 Views
5 Replies
  • Lisp
Replies (5)
Message 2 of 6

ВeekeeCZ
Consultant
Consultant

Post DWG as well.

What distance is measured in the second Distance to intersection column?

0 Likes
Message 3 of 6

Anonymous
Not applicable

Dwg attached below.

The second measurement is (in the first row, for example) the distance from start of the polyline in layer B to polyline in layer A. Other way to put this: I need to know how long A travels when hitting B and how long B travels when hitting A. The measurements are "doubled" in the excel example, but it isn't necessary. I just figured out if LISP program is to measure every possible intersection it will list both A->B and B->A.

0 Likes
Message 4 of 6

Sea-Haven
Mentor
Mentor

Two functions intersectwith and getpointatdist. Here is a start.

 

(defun c:distpt ( / obj1 obj2 intpt1 dist)
(setq obj1 (vlax-ename->vla-object (car  (entsel "Pick main line/pline"))))
(setq obj2 (vlax-ename->vla-object (car  (entsel "Pick crossing line/pline"))))
(setq intpt1 (vlax-invoke obj2 'intersectWith obj1 acExtendThisEntity))
(setq dist (vlax-curve-getdistatpoint obj1 intpt1))
(alert (strcat "Distance is " (rtos dist 2 2)))
(princ)
)

 

0 Likes
Message 5 of 6

ВeekeeCZ
Consultant
Consultant
Accepted solution

Ok.. this should do the trick.

 

(vl-load-com)

(defun c:ListPlineInters ( / *error* f LM:intersections s i o1 o2 j l)
  
  (defun *error* (errmsg)
    (if (not (wcmatch errmsg "Function cancelled,quit / exit abort,console break,end"))
      (princ (strcat "\nError: " errmsg)))
    (if f (close f))
    (princ))
  
  ;; Intersections  -  Lee Mac
  ;; Returns a list of all points of intersection between two objects
  ;; for the given intersection mode.
  ;; ob1,ob2 - [vla] VLA-Objects
  ;;     mod - [int] acextendoption enum of intersectwith method
  
  (defun LM:intersections ( ob1 ob2 mod / lst rtn )
    (if (and (vlax-method-applicable-p ob1 'intersectwith)
	     (vlax-method-applicable-p ob2 'intersectwith)
	     (setq lst (vlax-invoke ob1 'intersectwith ob2 mod)))
      (repeat (/ (length lst) 3)
	(setq rtn (cons (list (car lst) (cadr lst) (caddr lst)) rtn)
	      lst (cdddr lst))))
    (reverse rtn))
  
  ; -------------------------------------
  
  (if (setq s (ssget '((0 . "LWPOLYLINE,LINE"))))
    (repeat (setq i (sslength s))
      (setq o1 (vlax-ename->vla-object (ssname s (setq i (1- i)))))
      (repeat (setq j (sslength s))
	(setq o2 (vlax-ename->vla-object (ssname s (setq j (1- j)))))
	(if (and (not (equal o1 o2))
		 (setq l (LM:intersections o1 o2 acextendnone))
		 (or f
		     (and (setq f (open (strcat (getvar 'DWGPREFIX) "ListPlineInters.csv") "w"))
			  (write-line (write-line "Layer1;Dist1;Layer2;Dist2") f)))
		 )
	  (foreach x l
	    (write-line (write-line (strcat (vla-get-layer o1) ";" (rtos (vlax-curve-getdistatpoint o1 x) 2 1) ";" (vla-get-layer o2) ";" (rtos (vlax-curve-getdistatpoint o2 x) 2 1))) f))))))
  (*error* "end")
  )
0 Likes
Message 6 of 6

Anonymous
Not applicable

Did some testing and this is exactly what I was looking for. Thank you!

0 Likes