I am looking for an autolisp program or alternative way to move each vertex of a polyline so they are in line with one another but the distances separating each vertex remain the same. Essentially this would be like uncurling a polyline into a straight line. I cannot have a single straight line with the same total distance because I need the correct number of verteces and distances because I will eventually be using the point data in matlab for further processing.
@Anonymous wrote:
I am looking for an autolisp program or alternative way to move each vertex of a polyline so they are in line with one another but the distances separating each vertex remain the same. Essentially this would be like uncurling a polyline into a straight line. I cannot have a single straight line with the same total distance because I need the correct number of verteces and distances because I will eventually be using the point data in matlab for further processing.
Very basic, but see what you think:
(defun C:SPS (/ ss pl lengths); = Stretch Polyline(s) Straight
(prompt "\nTo Stretch Polylines out Straight,")
(if (setq ss (ssget '((0 . "*POLYLINE"))))
(progn ; 'then'
(repeat (setq n (sslength ss))
(setq pl (ssname ss (setq n (1- n))))
(repeat (setq par (fix (vlax-curve-getEndParam pl)))
(setq lengths ; list of segment lengths
(cons
(- ; length of segment ending at parameter
(vlax-curve-getDistAtParam pl par)
(vlax-curve-getDistAtParam pl (setq par (1- par)))
); -
lengths
); cons
); setq [lengths]
); repeat
(command "_.pline" (vlax-curve-getStartPoint pl))
(repeat (length lengths); feed segment lengths out to Pline
(command (polar (getvar 'lastpoint) 0 (car lengths)))
(setq lengths (cdr lengths))
); repeat
(command "")
); repeat
); progn
); if
); defun
It doesn't even turn off object snap or any of that stuff, yet, but it works in limited testing, on open or closed Polylines. It draws a straight Polyline in the 0-degree direction from the start of the selected one.
Hi @Anonymous,
Kent is always so quick with a good piece of code! You might also check the Autodesk App Store as there are many pline add-ins there too.
You might also want this thread to move to the customization forum - just let me know and I can do that for you.
Please select the Accept as Solution button if my post solves your issue or answers your question.
@Anonymous wrote:
Old thread, but this would be a helpful tool for me. Has anyone had any luck or found any other solutions?
Welcome to these Forums!
Does the code in Post 2 not work for you? If not, in what way does it not work?
Thank you for the reply and the code! There is just one kink, (excuse my articulation, it is early for me) when the beginning of the original polyline, which is the origin of the new line, will create a straight line that will intersect the original polyline (i.e. the end of the original polyline is in quadrant 1 assuming the origin is the beginning of the original polyline) it will create a notch at the intersection. Otherwise it is great!
@Anonymous wrote:
... There is just one kink ... when the beginning of the original polyline, which is the origin of the new line, will create a straight line that will intersect the original polyline (i.e. the end of the original polyline is in quadrant 1 assuming the origin is the beginning of the original polyline) it will create a notch at the intersection. ....
You must have running Object Snap modes on. Turn them off, or add this word:
(command "_none" (polar (getvar 'lastpoint) 0 (car lengths)))
Oh, that's what you meant by the function not turning snaps off, gotcha. Thanks again!
@Kent1Cooper wrote:
You must have running Object Snap modes on. Turn them off, or add this word:(command "_none" (polar (getvar 'lastpoint) 0 (car lengths)))
Strictly speaking, you should also add it here:
(command "_.pline" "_none" (vlax-curve-getStartPoint pl))
It may not make a difference for most people, since I expect most include ENDpoint as one of their usual running Osnap modes. But if, for example, you had MIDpoint but not ENDpoint running, or in some cases others such as CENter, it would start you off in the wrong place.
This lisp will work with any OSNAP (on or off).
(defun C:SPS (/ ss pl lengths newPl); = Stretch Polyline(s) Straight
(prompt "\nTo Stretch Polylines out Straight,")
(if (setq ss (ssget '((0 . "*POLYLINE"))))
(progn
(repeat (setq n (sslength ss))
(setq pl (ssname ss (setq n (1- n))))
(setq lengths (list) newPl (vl-cmdf "_.pline"))
(repeat (setq par (fix (vlax-curve-getEndParam pl)))
(setq lengths
(cons
(- (vlax-curve-getDistAtParam pl par)
(vlax-curve-getDistAtParam pl (setq par (1- par))))
lengths))
)
(vl-cmdf (vlax-curve-getStartPoint pl))
(foreach len lengths
(vl-cmdf "_non" (polar (getvar 'lastpoint) 0 len)) ; "_non"
)
(vl-cmdf "")
)
)
)
)
Can't find what you're looking for? Ask the community or share your knowledge.