Straighten curve with same length

Hi,
I have a few curves that I would like to convert into straight lines of the same length. Could you please help me do that?

For example the blue curves into black lines with similar lengths.

test.3dm (379.2 KB)

import Rhino
import scriptcontext

def UnrollCurve():
    rc, objref = Rhino.Input.RhinoGet.GetOneObject("Select curve", True, Rhino.DocObjects.ObjectType.Curve)
    if rc!=Rhino.Commands.Result.Success: return rc
    crv = objref.Curve()
    if not crv: return Rhino.Commands.Result.Failure
    line = Rhino.Geometry.Line(Rhino.Geometry.Point3d.Origin, Rhino.Geometry.Vector3d.XAxis, crv.GetLength())
    scriptcontext.doc.Objects.AddLine(line)
    scriptcontext.doc.Views.Redraw()
    return Rhino.Commands.Result.Success

if __name__=="__main__":
    UnrollCurve()

UnrollCurve.py (581 Bytes)

2 Likes

Thanks a lot. However, I can not use for multiple curves at a time. Could you please extend the code so that it can be used for multiple curves?

import Rhino
import scriptcontext

def UnrollCurve():
    rc, objs = Rhino.Input.RhinoGet.GetMultipleObjects("Select curves", True, Rhino.DocObjects.ObjectType.Curve)
    if rc!=Rhino.Commands.Result.Success: return rc
    y = 0
    for obj in objs:
        crv = obj.Curve()
        if not crv: return Rhino.Commands.Result.Failure
        line = Rhino.Geometry.Line(Rhino.Geometry.Point3d.Origin, Rhino.Geometry.Vector3d.XAxis, crv.GetLength())
        line.Transform(Rhino.Geometry.Transform.Translation(0, y, 0))
        y += 2
        scriptcontext.doc.Objects.AddLine(line)
    scriptcontext.doc.Views.Redraw()
    return Rhino.Commands.Result.Success

if __name__=="__main__":
    UnrollCurve()

UnrollCurve.py (719 Bytes)

That’s really great. You are an amazing coder. One more problem I am facing that I am getting all the curves at one place. Is there any way to have the each of the output curve in the same place of their original curve? It could be easier to track then. Maybe keeping the x ordinate value fixed or somehow else?

import Rhino
import scriptcontext

def UnrollCurve():
    rc, objs = Rhino.Input.RhinoGet.GetMultipleObjects("Select curves", True, Rhino.DocObjects.ObjectType.Curve)
    if rc!=Rhino.Commands.Result.Success: return rc
    for obj in objs:
        crv = obj.Curve()
        if not crv: return Rhino.Commands.Result.Failure
        line = Rhino.Geometry.Line(crv.PointAtStart, Rhino.Geometry.Vector3d.XAxis, crv.GetLength())
        scriptcontext.doc.Objects.AddLine(line)
    scriptcontext.doc.Views.Redraw()
    return Rhino.Commands.Result.Success

if __name__=="__main__":
    UnrollCurve()
1 Like