Hatch on the Layer of the Curve

Hello all,
i want create hatchs on the layer of the curves/surface. (i can use grasshopper to do that, but in this case/wish, i want to do it without grasshopper :))
in a sample file, i created 2 Layers: Layer 01 (green) and Layer 02 (gold).

here is the Python Script :

import Rhino
import scriptcontext as sc
from scriptcontext import doc
import System.Drawing
import rhinoscriptsyntax as rs

def PrintHatch(srf):
    layer = rs.ObjectLayer(srf)
    rs.CurrentLayer(layer)
    curves = rs.DuplicateSurfaceBorder(srf,1)
    hatch = rs.AddHatch(curves)
    rs.DeleteObjects(curves)

AllSrfs = rs.ObjectsByType(8 | 16, False, 0)

for i in AllSrfs:
    PrintHatch(i)

Can someone help me to chang the Pythonscript, or tell me, which RhinoCommand can i use to create the Hatchs on the layer of the curves/surfaces?

thank a lot!

Test for Hatch.3dm (423.2 KB)

Hi,
Here is a solution that seems to work :

import rhinoscriptsyntax as rs

def PrintHatch(srf):
    layer = rs.ObjectLayer(srf)
    curves = rs.DuplicateEdgeCurves(srf,1)
    joinedCurves = rs.JoinCurves(curves)
    hatch = rs.AddHatches(joinedCurves)
    rs.ObjectLayer(hatch, layer)
    rs.DeleteObjects(joinedCurves)
    rs.DeleteObjects(curves)

AllSrfs = rs.ObjectsByType(8 | 16, False, 0)
rs.EnableRedraw(False)

for i in AllSrfs:
    PrintHatch(i)
  1. Use rs.AddHatches() to handle multiple curves
  2. rs.DuplicateSurfaceBorder() seems to extract only external curve, use rs.DuplicateEdgeCurves() instead.
  3. You have to join the edge curves to obtain planar closed curves
  4. I also changed the way to set the object’s layer. It avoids changing the active layer of your model.
  5. I like to disable the redraw with rs.EnableRedraw(False) at the beginning of a script. It runs faster.

thank you very much for your cooooool post!!!:grinning:

Hello,

This seems really nice! I’m also looking in generating hatches on the layers of the curves.
It would be very helpful to retain the layers when applying the hatch command to multiple curves.

Can you help me to understand this?
Thanks for you help!

OK, that was a bit confusing because the topic titles didn’t mention sufaced. And I was more interested in the curves.

So here’s a script that creates hatches from closed curves and places them directly in the same layer as the selected curves. If it helps anyone else.

HatchOnCurveLayer.py (748 Bytes)