Help: Need a Flow along curve tool

Hi guys, I am trying to make a “flow along cuve” tool but I am hitting walls…
The only tool I found was the “Rhino.Geometry.Curve.FlowSpaceMorph()” but I can’t seem to get it right.

Thanks for any help!

(This is a small part of a project curved curve onto geometry and then make a straight line with the length of the projected curve and then flow the projection onto the straight line)

Here’s what I have tried:

import rhinoscriptsyntax as rs
import Rhino
import scriptcontext as sc

def flowObject():
    rc, crv_id = Rhino.Input.RhinoGet.GetOneObject("Select curve", False, Rhino.DocObjects.ObjectType.Curve)
    if rc!=Rhino.Commands.Result.Success: return
    curve = crv_id.Curve()
    flow_id = rs.GetObject("Backbone")
    if not flow_id:
    flow = rs.coercecurve(flow_id)
    length = flow.GetLength()
    print length
    # .GetCurveParameterFromNurbsFormParameter
    newCrv = curve.FlowSpaceMorph(flow, line, False)
    sc.doc.Objects.Replace(crv_id, newCrv)



Curve.SetStartPoint and .SetEndPoint are better suited for tweaking the ends of existing valid curves.
Instead, create the linear curve more directly such as

line = Rhino.Geometry.NurbsCurve.Create(
    points=rs.coerce3dpointlist(((0,0,0), (length,0,0))))

Then use FlowSpaceMorph like this

crv_WIP = curve.DuplicateCurve() # Good to do this since curve.IsDocumentControlled == True.
fsm = Rhino.Geometry.Morphs.FlowSpaceMorph(flow, line, False)
sc.doc.Objects.Replace(crv_id, crv_WIP)

Hi @Holo and @spb, or create a LineCurve directly:

import Rhino
import scriptcontext
import rhinoscriptsyntax as rs

def DoSomething():
    flow_crv_id = rs.GetObject("Curve to flow", 4, True, False)
    if not flow_crv_id: return
    backbone_crv_id = rs.GetObject("Backbone curve", 4, False, False)
    if not backbone_crv_id: return
    crv_to_flow = rs.coercecurve(flow_crv_id)
    backbone_crv = rs.coercecurve(backbone_crv_id, -1, True)
    p0 = Rhino.Geometry.Point3d.Origin
    p1 = Rhino.Geometry.Point3d(backbone_crv.GetLength(), 0, 0)
    line_crv = Rhino.Geometry.LineCurve(p0, p1)
    morph = Rhino.Geometry.Morphs.FlowSpaceMorph(backbone_crv, line_crv, True)
    if morph.IsValid:
        morph.Morph(crv_to_flow )


Thanks so much guys!
I had no idea space morph was sat up as a separate “portal” that could be reused, and would probably not have figured it out either. And that is great as now I can set it up once and pass all kinds of stuff through it :smiley: