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?
Please open this GIF video in a new tab of your browser. It will show bigger.
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()
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.