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:
        return
    flow = rs.coercecurve(flow_id)
    
    length = flow.GetLength()
    print length
    
    
    
    # .GetCurveParameterFromNurbsFormParameter
    
    line=Rhino.Geometry.NurbsCurve(1,2)
    #line.Degree=1
    line.SetStartPoint(rs.coerce3dpoint((0,0,0)))
    line.SetEndPoint(rs.coerce3dpoint((length,0,0)))
    
    
    newCrv = curve.FlowSpaceMorph(flow, line, False)
    
    
    sc.doc.Objects.Replace(crv_id, newCrv)

flowObject()



#Rhino.Geometry.Morphs.FlowSpaceMorph()

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(
    periodic=False,
    degree=1,
    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)
fsm.Morph(crv_WIP)
sc.doc.Objects.Replace(crv_id, crv_WIP)
sc.doc.Views.Redraw()

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 )
        scriptcontext.doc.Objects.AddCurve(crv_to_flow)
        scriptcontext.doc.Views.Redraw()
    
DoSomething()

_
c.

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: