Problem extruding planar surface with Rhino Python

Hi all,

i want to create a 3D Extrusion of a text element.
My script does NOT raise any errors, it just does not show me an extruded 3d Object in Rhino, the text stays a flat planar surface…
Thanks in advance.

Greets
Mr. Sinter

Code:

    import rhinoscriptsyntax as rs
import Rhino as rhi

#CREATE TEXT AS PLANAR SRF
zero = (0,0,0)
text_guid = rs.AddText("NAME", zero, height=20.0, font="Arial")
text_in_curves = rs.ExplodeText(text_guid, delete=True)
text_as_srf = rs.AddPlanarSrf(text_in_curves)
#CREATE TEXT AS PLANAR SRF

#DELETE TEXT OUTLINE CURVES
fubar = 0
for element in text_in_curves:
 rs.DeleteObject(text_in_curves[fubar])
 fubar = fubar + 1
#DELETE TEXT OUTLINE CURVES

#CREATE EXTRUDE PATH
extrude_path = rs.AddLine((0,0,0), (0,0,10))
objectref_path = rhi.DocObjects.ObjRef(extrude_path)
path_curve = rhi.DocObjects.ObjRef.Curve(objectref_path)
#CREATE EXTRUDE PATH

#EXTRUDE SRF ALONG PATH
foo = 0
for element in text_as_srf:
 object_reference = rhi.DocObjects.ObjRef(text_as_srf[foo])
 brep_face = rhi.DocObjects.ObjRef.Face(object_reference)
 print "%s"%brep_face
 brep_extrude = rhi.Geometry.BrepFace.CreateExtrusion(brep_face, path_curve, True)
 print "%s"%brep_extrude
 foo = foo + 1
#EXTRUDE SRF ALONG PATH

#DELETE EXTRUDE PATH
rs.DeleteObject(extrude_path)

Rhinoscriptsyntax methods generally work with objects already in the document and their result usually also generally adds the objects automatically to the document. RhinoCommon methods do not. So you have created your extrusion with

Geometry.BrepFace.CreateExtrusion()

but you have not added it to the document, so at the end of the script, it just “evaporates”.

Generally, communication with the active document is done via scriptcontext. I added a few lines to your script below to show you how it works:

import rhinoscriptsyntax as rs
import Rhino as rhi
import scriptcontext as sc

#CREATE TEXT AS PLANAR SRF
zero = (0,0,0)
text_guid = rs.AddText("NAME", zero, height=20.0, font="Arial")
text_in_curves = rs.ExplodeText(text_guid, delete=True)
text_as_srf = rs.AddPlanarSrf(text_in_curves)
#CREATE TEXT AS PLANAR SRF

#DELETE TEXT OUTLINE CURVES
fubar = 0
for element in text_in_curves:
 rs.DeleteObject(text_in_curves[fubar])
 fubar = fubar + 1
#DELETE TEXT OUTLINE CURVES

#CREATE EXTRUDE PATH
extrude_path = rs.AddLine((0,0,0), (0,0,10))
objectref_path = rhi.DocObjects.ObjRef(extrude_path)
path_curve = rhi.DocObjects.ObjRef.Curve(objectref_path)
#CREATE EXTRUDE PATH

#EXTRUDE SRF ALONG PATH
foo = 0
for element in text_as_srf:
 object_reference = rhi.DocObjects.ObjRef(text_as_srf[foo])
 brep_face = rhi.DocObjects.ObjRef.Face(object_reference)
 print "%s"%brep_face
 brep_extrude = rhi.Geometry.BrepFace.CreateExtrusion(brep_face, path_curve, True)
 print "%s"%brep_extrude
 #******************************************
 #add your object to the document here
 sc.doc.Objects.AddBrep(brep_extrude)

 #Delete the surface object
 rs.DeleteObject(element)
 #******************************************
 foo = foo + 1
#EXTRUDE SRF ALONG PATH

#DELETE EXTRUDE PATH
rs.DeleteObject(extrude_path)

#Redraw the screen
sc.doc.Views.Redraw()

HTH, --Mitch

Thanks Mitch for that immediate reply.
I was running into trouble as I got no error msg…

Now I can further improve my script to apply Grasshopper Voronoi functions on my 3D Text object…

Kind Regards,
Mr Sinter

And, here is a script that basically does the same thing, only with a different approach.

https://github.com/mcneel/rhinoscript/blob/master/ConvertTextToGeometry.rvb