Measure partial distance along polyline?

Measure partial distance along polyline?

mbloswick
Enthusiast Enthusiast
682 Views
10 Replies
Message 1 of 11

Measure partial distance along polyline?

mbloswick
Enthusiast
Enthusiast

I have received some points along a polyline, and I need to know the "path distance" between them.

Here's an example:

mbloswick_0-1735855008916.png

What tool can I use to find the distance along the polyline between the two points? If there's not a tool (?!?) is there a LISP floating around? My search here didn't turn up anything, but I could be asking the wrong question.

Thank you.

 

 

0 Likes
Accepted solutions (1)
683 Views
10 Replies
Replies (10)
Message 2 of 11

pendean
Community Legend
Community Legend

@mbloswick wrote:

...is there a LISP floating around? My search here didn't turn up anything...

 

 


Here is one post I found with not much effort with many ideas (untested here), have you seen it? What was wrong with those tips for example?

https://www.cadtutor.net/forum/topic/63780-determine-distance-between-points-on-an-entity/

 

0 Likes
Message 3 of 11

mbloswick
Enthusiast
Enthusiast

My Search mojo must not have rolled over into the new year. Thank you. I'll see if I can get my head around it.

0 Likes
Message 4 of 11

Sea-Haven
Mentor
Mentor

This is a simple version, try it. I did not take into account how your picking points. If its circles etc the code can be made to choose those.

 

(defun c:wow ( / pt1 pt2 d1 d2)
(setq ent (entsel "\nPick point 1 "))
(setq pt1 (cadr ent))
(setq obj (vlax-ename->vla-object (car ent)))
(setq pt1 (vlax-curve-getclosestpointto obj pt1))
(setq pt2 (getpoint "\nPick point 2 "))
(setq d1 (vlax-curve-getdistatpoint obj pt1))
(setq d2 (vlax-curve-getdistatpoint obj pt2))
(setq dist (abs (- d1 d2)))
(alert (strcat "distance is " (rtos dist 2 3) " between the 2 points"))
(princ)
)
(c:wow)

 

0 Likes
Message 5 of 11

john.uhden
Mentor
Mentor

@Sea-Haven ,

With that there is no guarantee that pt2 is on the polyline.

I have too often found that (vlax-curve-getdistatpoint e p)

needs to be:

(vlax-curve-getdistatpoint e (vlax-curve-getclosestpointto e p))

John F. Uhden

Message 6 of 11

CADaSchtroumpf
Advisor
Advisor

An another version, my tool!

(defun draw_pt (pt col / rap)
	(setq rap (/ (getvar "viewsize") 50))
	(foreach n
		(mapcar
			'(lambda (x)
				(list
					((eval (car x)) (car pt) rap)
					((eval (cadr x)) (cadr pt) rap)
					(caddr pt)
				)
			)
			'((+ +) (+ -) (- +) (- -))
		)
		(grdraw pt n col)
	)
)
(defun c:partial_length_on_curv ( / js ent vlaobj pt_brk pt_brk2 abs_curv1 abs_curv2 lg_curv)
	(vl-load-com)
	(princ "\nSelect a curvilinear object on which you want to perform a measurement.")
	(while
		(not
			(setq js
				(ssget "_+.:E:S"
					(list
						(cons -4 "<OR")
							(cons -4 "<AND")
								(cons 0 "*POLYLINE,LINE,ARC,CIRCLE,ELLIPSE")
								(cons -4 "<NOT")
									(cons -4 "&") (cons 70 112)
								(cons -4 "NOT>")
							(cons -4 "AND>")
							(cons 0 "SPLINE")
						(cons -4 "OR>")
					)
				)
			)
		)
	)
	(redraw (setq ent (ssname js 0)) 3)
	(setq
		vlaobj (vlax-ename->vla-object ent)
	)
	(while (setq pt_brk (getpoint "\nChoice of the point of origin of the measurement: "))
		(setq pt_brk (vlax-curve-getClosestPointTo vlaobj (trans pt_brk 1 0)))
		(cond
			(pt_brk
				(draw_pt (trans pt_brk 0 1) 3)
				(initget 9)
				(setq pt_brk2 (getpoint "\nChoice of end point of measurement: "))
				(setq pt_brk2 (vlax-curve-getClosestPointTo vlaobj (trans pt_brk2 1 0)))
				(if pt_brk2
					(progn
						(setq
							absc_curv1 (vlax-curve-getDistAtPoint vlaobj pt_brk)
							absc_curv2 (vlax-curve-getDistAtPoint vlaobj pt_brk2)
							lg_curv (- (max absc_curv1 absc_curv2) (min absc_curv1 absc_curv2))
						)
						(princ (strcat "\nCurvilinear length = " (rtos lg_curv 2 8)))
						(redraw)
					)
				)
			)
		)
	)
	(redraw ent 4)
	(prin1)
)
0 Likes
Message 7 of 11

Kent1Cooper
Consultant
Consultant

Are the "points" POINT OBJECTS specifically?  Or CIRCLEs?  or BLOCK references?  Or just XY [or XYZ] coordinates that you are given somehow?  Or...?

Kent Cooper, AIA
0 Likes
Message 8 of 11

mbloswick
Enthusiast
Enthusiast

Thank you!

I'm barely familiar with LISP. What is the command I type to run this after loading?

Thank you!

0 Likes
Message 9 of 11

CADaSchtroumpf
Advisor
Advisor
Accepted solution

The command is: partial_length_on _curv

 

At your convenience, you can change  

(defun c:partial_length_on_curv

 

(defun c:your_command

 

0 Likes
Message 10 of 11

mbloswick
Enthusiast
Enthusiast

Perfect, and it works like a charm. Thank you!

0 Likes
Message 11 of 11

calderg1000
Mentor
Mentor

Regards @mbloswick 

If you are trying to find the partial distance between CAD points inserted in a polyline, here is an option.

 

;;;___
(defun c:Dpl (/ s ln j lp sl pm k lp ld lpr lt prm y z pm a)
  (while
    (not (equal (setq s (ssget '((0 . "Point,Lwpolyline")))) nil))
     (setq ln
            (vl-remove-if 'listp
                          (mapcar 'cadr (ssnamex s))
            )
     )
     (foreach j ln
       (if (= (cdr (assoc 0 (entget j))) "POINT")
         (setq lp (cons (cdr (assoc 10 (entget j))) lp)
         )
         (setq sl (vlax-ename->vla-object j))
       )
     )
     (setq pm (mapcar '(lambda (u w) (* (+ u w) 0.5)) (car lp) (cadr lp)))
     (foreach k lp
       (setq ld  (cons (vlax-curve-getdistatpoint sl k) ld)
             lpr (cons (vlax-curve-getparamatpoint sl k) lpr)
       )
     )
     (setq lt  (abs (apply '- ld))
           prm (apply '(lambda (y z) (* (+ y z) 0.5)) lpr)
           pm  (vlax-curve-getpointatparam sl prm)
           a   (angle '(0 0 0) (vlax-curve-getfirstderiv sl prm))
     )
     (entmakex (list '(0 . "Text")
                     (cons 10 pm)
                     (cons 1 (rtos lt 2 2))
                     (cons 40 2.5);...Htext
                     (cons 50 a)
               )
     )
     (setq ln  nil
           lp  nil
           ld  nil
           lpr nil
     )
     (princ lt)
  )
)

 

 

Distancia Parcial entre puntos CAD sobre curva Lwpolyline.gif

 


Carlos Calderon G
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.

0 Likes