AddHatch not baking Model Hatch with python component

Hi all
I know there are a few posts on this already but I cant quite find what I’m looking for, maybe someone can help.

What would the correct ghpython approach be, using RhinoCommon, to bake a hatch defined with the gh Model Hatch component?
Nothing I have tried seems to actually add anything to the rhino file.
Im not sure if I actually have to create the hatch in the script, but the component supplies an object of type hatch already…

Attached the gh script and below one of the code approaches I have tried:

import Rhino

active_doc = Rhino.RhinoDoc.ActiveDoc

for hatch in i_hatches:
    attr = Rhino.DocObjects.ObjectAttributes()
    active_doc.Objects.AddHatch(hatch, attr)

active_doc.Views.ActiveView.Redraw()

HatchBake.gh (9.9 KB)

We have added a few new components and tools in Rhino 9 WIP Grasshopper to edit and create Hatch patterns that may work. New Component: Create Hatch patterns with Grasshopper in Rhino 9

Hi @Tom_D ,

This script should work.

import Rhino
import Grasshopper.Kernel as GK
from Grasshopper.Rhinoceros.Model import *

active_doc = Rhino.RhinoDoc.ActiveDoc

for obj in i_objects:
    # Convert input to a ModelObject
    # If input is already a ModelObject it will preserve all attributes (Layer, Color, Material, etc...)
    modelObject = ModelObject.Cast(obj) 
    # Bake the resulting ModelObject
    GK.IGH_BakeAwareData(modelObject).BakeGeometry(active_doc, None)

Be sure to use a ModelObject to keep all the properties in this case the hatch-pattern.

Thank you @scottd I will check it out…

Thanks @kike this is very useful, I hadnt been able to ind this elsewhere on the forum…