Community
AutoCAD Forum
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Uncurling polyline into straight line?

10 REPLIES 10
Reply
Message 1 of 11
Anonymous
2406 Views, 10 Replies

Uncurling polyline into straight line?

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.

10 REPLIES 10
Message 2 of 11
Kent1Cooper
in reply to: Anonymous


@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.

Kent Cooper, AIA
Message 3 of 11
Anonymous
in reply to: Kent1Cooper

Thank you very much. I'll give it a try

Message 4 of 11
Anonymous
in reply to: Anonymous

Old thread, but this would be a helpful tool for me. Has anyone had any luck or found any other solutions?

Message 5 of 11
john.vellek
in reply to: Anonymous

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.


John Vellek


Join the Autodesk Customer Council - Interact with developers, provide feedback on current and future software releases, and beta test the latest software!

Autodesk Knowledge Network | Autodesk Account | Product Feedback
Message 6 of 11
Kent1Cooper
in reply to: Anonymous


@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?

Kent Cooper, AIA
Message 7 of 11
Anonymous
in reply to: Kent1Cooper

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!

 

 

 

Message 8 of 11
Kent1Cooper
in reply to: Anonymous


@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)))

Kent Cooper, AIA
Message 9 of 11
Anonymous
in reply to: Kent1Cooper

Oh, that's what you meant by the function not turning snaps off, gotcha. Thanks again!

Message 10 of 11
Kent1Cooper
in reply to: Kent1Cooper


@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.

Kent Cooper, AIA
Message 11 of 11
ichernitsky
in reply to: Anonymous

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.

Post to forums  

Autodesk Design & Make Report

”Boost