I have a workflow where I am baking hatches using C# and I have found that Rhino 8/Grashopper will only bake hatches if they are referenced, or internalized from a referenced hatch from Rhino. Rhino 8 will NOT bake hatches if they are created within Grasshopper. See the attached video showing the issue. See the attached Grasshopper file where you can (hopefully) recreate the issue.
The only thing I can think is there is some difference with GH_Hatches vs Hatches? Not sure. I am using Rhino.RhinoDoc.ActiveDoc.Objects.Add(hatch); as the method in C# to bake the hatches to Rhino.
Yes the content cache component works. But I have to have this in C#, as this is part of a component in a plugin.
How can I implement this behavior in C#? I saw this thread but it is not very explanatory on how to actually implement the Content Cache component behavior in C#.
Is this the intended behavior btw? It seems like using the content cache is a workaround because adding to the document through c# doesn’t work correctly. It certainly feels like a bug to me as a user, since there is not explanation of why it doesn’t work.
I was able to find a solution using IGH_BakeAwareData.BakeGeometry
private void RunScript(Hatch hatch, bool run, ref object a)
{
if(run) {
GH_Hatch h = new GH_Hatch(hatch);
var attrs = new ObjectAttributes();
if (h is IGH_BakeAwareData bakeAware)
{
bakeAware.BakeGeometry(Rhino.RhinoDoc.ActiveDoc, attrs, out Guid id);
}
}
}
This will bake hatches whether they are referenced, internalized, or created in Grasshopper.
I still feel like not being able to use Rhino.RhinoDoc.ActiveDoc.Objects.Add(); or Rhino.RhinoDoc.ActiveDoc.Objects.AddHatch(); to bake hatches created in Grasshopper (without even raising an error or warning or any messaging regarding the reason it doesn’t work) is a bug. But I’ve found a workaround.