BendSpaceMorph example in python

I am trying to bend some text in an arc with a given radius. I can accomplish this manually with the bend command inside of rhino, but my goal is to automate this task with python. Here is a snippet of my code that I am writing to accomplish this, but it does not work. (The text stays planar)

text_object = rs.AddText(text, rs.ViewCPlane("Front"), height=text_height, font=font, font_style=font_style, justification=131074)
text_curves = rs.ExplodeText(text_object)
text_surfaces = rs.AddPlanarSrf(text_curves)
line = rs.AddLine((0, 0, 0), (0, -1, 0))
text_solids = [rs.ExtrudeSurface(srf, line) for srf in text_surfaces]
rs.MoveObjects(text_solids, (0, radius, 0))
morph = Rhino.Geometry.Morphs.BendSpaceMorph(
        Rhino.Geometry.Point3d(0, radius, 0),
        Rhino.Geometry.Point3d(100, radius, 0),
        Rhino.Geometry.Point3d(radius, 0, 0),
        True,
        True)
[morph.Morph(rs.coercebrep(s)) for s in text_solids]

I do not get an error or crash, but the text in the scene remains uncurved.

Let me know if any more information is needed.

Hi @Jack_Minardi,

There simple example that works in Rhino 6:

import Rhino
import rhinoscriptsyntax as rs
import scriptcontext as sc

rs.EnableRedraw(False)
rs.Command('_-TextObject _HorizontalAlignment=_Left _VerticalAlignment=_Bottom _CreateGeometry=_Solids "Hello Rhino!" 0')
obj_ids = rs.LastCreatedObjects()
if obj_ids:
    bbox = rs.BoundingBox(obj_ids)
    start = Rhino.Geometry.Point3d.Origin
    end = bbox[1]
    point = bbox[2]
    morph = Rhino.Geometry.Morphs.BendSpaceMorph(start, end, point, True, True)
    for id in obj_ids:
        brep = rs.coercebrep(id)
        morph.Morph(brep)
        sc.doc.Objects.Replace(id, brep)
rs.EnableRedraw(True)

Hope this helps.

– Dale

1 Like

Thanks, sc.doc.Objects.Replace(id, brep) was the missing part that I needed. Everything works as expected now.