View Full Version : Lenght of polyline from specific point to specific point?!
marijan.marsic
2007-10-05, 02:08 PM
Is it possible to make lisp routine to do next:
Give lenght of polyline from one specific start point somewhere on poliyline to next specific point on same polyline. (This points are not startpoint or endpoint of polyline).
Thanks a lot !!
(Forrest Gump: My momma always said, "Life was like a box of chocolates. You never know what you're gonna get.")
Mike_R
2007-10-05, 02:46 PM
Why not just use the distance command with the nearest (NEA) Osnap?
marijan.marsic
2007-10-05, 02:54 PM
P0lyline made of arcs segments; distance command gives a length from point to point (linear); I need lenght of curve (polyline) or spline from point to point.
But thanks anyway!!
Try this one
(defun lp (/ d1 d2 leng obj p1 p2 par1 par2 ss)
(vl-load-com)
(if (and (setq p1 (getpoint "\n Specify first point: "))
(setq p2 (getpoint "\n Specify second point: ")))
(progn
(if
(setq ss (ssget "_C" (trans p1 1 0) (trans p1 1 0)(list (cons 0 "*POLYLINE"))))
(progn
(if (= (sslength ss) 1)
(progn
(setq obj (vlax-ename->vla-object (ssname ss 0)))
(setq par1 (vlax-curve-getparamatpoint obj
(vlax-curve-getclosestpointto obj p1))
par2 (vlax-curve-getparamatpoint obj
(vlax-curve-getclosestpointto obj p2))
)
(setq d1 (vlax-curve-getdistatparam obj par1)
d2 (vlax-curve-getdistatparam obj par2)
)
(cond ((equal d2 d1 0.00001)
(setq leng 0.0))
((> d2 d1)
(setq leng (abs (- d2 d1))))
((> d2 d1)
(setq leng (abs (- d1 d2))
)))
)
(princ "\nMore than 1 polylines selected")
)
)
(princ "\n0 polylines selected")
)
)
(princ "\n1 or both poins not sopecified")
)
leng
)
(defun C:test()
(setq d (lp))
(alert (strcat "Length: \n"(vl-princ-to-string d)))
)
marijan.marsic
2007-10-09, 04:04 PM
Try this one
Thanks!
IT WORKS!!!
Glad if that help
Cheers :)
~'J'~
CAB2k
2007-10-10, 05:57 PM
Fatty,
Here is a variation of your routine.
(defun lp (/ p1 p2 e1 e2 len)
(vl-load-com)
(while
(not
(and
(setq p1 (getpoint "\n Specify first point: "))
(or (setq e1 (car (nentselp p1)))
(prompt "\n** Missed, Try again.")
)
(or (not (vl-catch-all-error-p
(vl-catch-all-apply
'vlax-curve-getpointatparam
(list e1 0.0)
)
)
)
(prompt "\n** Wrong object type, Try again.")
)
)
)
)
(while
(not
(and
(setq p2 (getpoint "\n Specify second point: "))
(or (setq e2 (car (nentselp p2)))
(prompt "\n** Missed, Try again.")
)
(or (equal e1 e2)
(prompt "\n** Not the same object, Try again.")
)
)
)
)
(setq p1 (vlax-curve-getclosestpointto e1 p1)
p2 (vlax-curve-getclosestpointto e1 p2)
)
(setq len
(abs (- (vlax-curve-getdistatparam e1 (vlax-curve-getparamatpoint e1 p1))
(vlax-curve-getdistatparam e1 (vlax-curve-getparamatpoint e1 p2))
)
)
)
len
)
(defun C:test ()
(setq d (lp))
(alert (strcat "Length: \n" (vl-princ-to-string d)))
)
Thanks Alan,
Your routine does work much better
than mine :)
Regards,
Oleg
CAB2k
2007-10-10, 10:05 PM
Thanks Oleg, Just another way to skin the cat.:)
marijan.marsic
2007-10-11, 10:26 AM
Thanks Oleg, Just another way to skin the cat.:)
Is it possible to modify this routine to add a possibility for puting that lenght as a text somwehre in drawing.
( Near to polyline or on any place in drawing)???
Mike_R
2007-10-11, 03:06 PM
Just take the return value, len, and then create a text object with that as the contents using something like entmake or vla-add.
marijan.marsic
2007-10-17, 08:55 AM
It works, just fine for me!
Thank you all ! !
vBulletin® v3.6.7, Copyright ©2000-2009, Jelsoft Enterprises Ltd.