HatchPatterns table (RhinoCommon) does not show properly

Hi there,

I have a question about the HatchPatterns Table in RhinoCommon which we can access with the code “Rhino.RhinoDoc.ActiveDoc.HatchPatterns”.

When I make a new empty Rhino file. and I get the hatch pattern tabel via rhinocommon.
But it shows the hatch pattern is empty.
And then I type the “Option” command and show the Hatch pattern in Rhino. And Again I get the hatch pattern tabel via rhinocommon.
This time, it shows the hatch pattern table properly.

I attach the video to explain this process.

I am wondering if this is a bug or if I mistook some steps?
Animation

Please open this GIF video in a new tab of your browser. It will show bigger.

This table is left empty unless the user needs it. Same for line types.

1 Like

When I open my Grasshopper definition, it accesses this table. But it is empty.
How can I avoid it so?

Thank you so much.

The hatch table is empty in every new 3dm file and hatches are added to it when requested.

You can do something like this using RhinoCommon and load in the hatches when you need them.

Your code could do something like this in order to determine when and if you need to to load various hatches. This example assumes there are 0 hatches and then loads the entire default collection, but you could modify to be selective about which patterns you want to load should you desire.

import Rhino

def load_default_hatch_patterns():
    # Get the RhinoCommon document
    doc = Rhino.RhinoDoc.ActiveDoc
    
    # Check if the hatch table count is zero
    if doc.HatchPatterns.Count == 0:
        # List of default hatch patterns
        default_patterns = [
            Rhino.DocObjects.HatchPattern.Defaults.Solid,
            Rhino.DocObjects.HatchPattern.Defaults.Hatch1,
            Rhino.DocObjects.HatchPattern.Defaults.Hatch2,
            Rhino.DocObjects.HatchPattern.Defaults.Hatch3,
            Rhino.DocObjects.HatchPattern.Defaults.Dash,
            Rhino.DocObjects.HatchPattern.Defaults.Grid,
            Rhino.DocObjects.HatchPattern.Defaults.Grid60,
            Rhino.DocObjects.HatchPattern.Defaults.Plus,
            Rhino.DocObjects.HatchPattern.Defaults.Squares
        ]
        
        # Add each pattern if it doesn't exist
        for pattern in default_patterns:
            hatch_id = doc.HatchPatterns.Find(pattern.Name, True)
            if hatch_id == -1:
                doc.HatchPatterns.Add(pattern)

# Call the function to load default hatch patterns
load_default_hatch_patterns()
2 Likes

I see !!
Perfect !! Thank you very much !!
It is tricky. But i resolved !

I wish HatchPatterns has information from the opening new rhino file.

Thanks !

Rhino does this as to not bloat a 3dm file with data that it’s not using. Even Rhino itself does a similar process for dealing with hatches. The Purge command will also debloat unused hatches and other object types that might be in the 3dm and unused.

1 Like

I see.
Rhino has family circumstances.
I understand. I am happy your solution anyway.

Thank you so much foryour quick rply !

1 Like