Hi @piac, thanks for the suggestion. I tried your code snippet and it seems to have fixed the bake issue.
You can see that you imported System not “as sy”, so this will not work.
Okay, that’s my mistake. I did try adding System previously and with the correct import names, but was getting no response then (most likely as I did not understand what to return in case of an exception). I was also stuck on what you meant by ‘most-encompassing level’, plus this bit:
except Exception, ex:
System.Windows.Forms.MessageBox.Show(str(ex))
return False, System.Guid.Empty
So for the learning bit: How does returning (False, System.Guid.Empty) change things? From what I understand, is that if the main body catches an exception (like when a Text object doesn’t work or something), then the BakeGeometry function will signal to Gh to not add anything and an empty Guid will be caught. I’m not too familiar with the inner workings of Gh’s work flow, so how do these return values allow Gh to bake the geometry (even the Text Object)?
Update: So adding a ‘try-except’ with a ‘return False, System Guid.Empty’ appears to solve the bake issue completely. Much thanks again to @piac and @DavidRutten for their help.
Here’s the final code snippet, in case it helps anyone else:
import Rhino as r
import Grasshopper.Kernel as gh
import System as sy
class TextGoo(gh.Types.GH_GeometricGoo[r.Display.Text3d], gh.IGH_BakeAwareData, gh.IGH_PreviewData):
#region construction
def __init__(self, text):
self.m_value = text
@staticmethod
def DuplicateText3d(original):
if original is None: return None
text = r.Display.Text3d(original.Text, original.TextPlane, original.Height)
text.Bold = original.Bold,
text.Italic = original.Italic,
text.FontFace = original.FontFace
return text
def DuplicateGeometry(self):
return TextGoo(TextGoo.DuplicateText3d(self.m_value))
#region properties
def get_TypeName(self):
return "3D Text"
def get_TypeDescription(self):
return "3D Text"
def ToString(self):
if self.m_value is None: return "<null>"
return self.m_value.Text
def get_Boundingbox(self):
if self.m_value is None:
return r.Geometry.BoundingBox.Empty;
return self.m_value.BoundingBox;
def GetBoundingBox(self, xform):
if self.m_value is None:
return r.Geometry.BoundingBox.Empty
box = self.m_value.BoundingBox
corners = xform.TransformList(box.GetCorners())
return r.Geometry.BoundingBox(corners)
#region methods
def Transform(self, xform):
text = TextGoo.DuplicateText3d(self.m_value)
if text is None: return TextGoo(None)
plane = text.TextPlane
point = plane.PointAt(1, 1)
plane.Transform(xform)
point.Transform(xform)
dd = point.DistanceTo(plane.Origin)
text.TextPlane = plane;
text.Height *= dd / sqrt(2)
return TextGoo(text)
def Morph(self, xmorph):
return self.DuplicateGeometry()
#region preview
def get_ClippingBox(self):
return self.get_Boundingbox()
def DrawViewportWires(self, args):
if self.m_value is None: return
args.Pipeline.Draw3dText(self.m_value, args.Color)
def DrawViewportMeshes(self, args):
# Do not draw in meshing layer.
pass
#region baking
def BakeGeometry(self, doc, att, id):
try:
id = sy.Guid.Empty
if self.m_value is None:
return false, id
if att is None:
att = doc.CreateDefaultAttributes()
id = doc.Objects.AddText(self.m_value, att)
return True, id
except Exception, ex:
sy.Windows.Forms.MessageBox.Show(str(ex))
return False, sy.Guid.Empty