Get hatch boundary

Hi i try to get hatch boundry in hatch in rhino by grasshopper
But i don’t know select hatch in Rhino and (set)
that (import hatch )in grasshopper please help me and What is hatch input in c# component?
For example is hatch geometry Base data or ???generic data ,…

Hi @Rh-3d-p,

Is this helpful?

import Rhino
import scriptcontext as sc

def test_hatch_boundary():
    go = Rhino.Input.Custom.GetObject()
    go.SetCommandPrompt("Select hatches")
    go.GeometryFilter = Rhino.DocObjects.ObjectType.Hatch
    go.GroupSelect = True
    go.SubObjectSelect = False
    go.GetMultiple(1, 0)
    if go.CommandResult() != Rhino.Commands.Result.Success: return
    
    for objref in go.Objects():
        hatch = objref.Hatch()
        if hatch:
            curves = hatch.Get3dCurves(True)
            for curve in curves:
                sc.doc.Objects.AddCurve(curve)
    sc.doc.Views.Redraw()
    
if __name__ == "__main__":
    test_hatch_boundary()

– Dale

Hi thanks
But i don’t need use scriptcontext and python
I need to slove in c#. For write plugin .

The code for C# plug-in command isn’t much different.

protected override Result RunCommand(RhinoDoc doc, RunMode mode)
{
  var go = new GetObject();
  go.SetCommandPrompt("Select hatches");
  go.GeometryFilter = Rhino.DocObjects.ObjectType.Hatch;
  go.GroupSelect = true;
  go.SubObjectSelect = false;
  go.GetMultiple(1, 0);
  if (go.CommandResult() != Rhino.Commands.Result.Success)
    return go.CommandResult();

  foreach (var objref in go.Objects())
  {
    var hatch = objref.Hatch();
    if (null != hatch)
    {
      var curves = hatch.Get3dCurves(true);
      foreach (var curve in curves)
        doc.Objects.AddCurve(curve);
    }
  }

  doc.Views.Redraw();

  return Result.Success;
}

– Dale

hi @dale again
If I want to run in Grasshopper
What should I enter in the using section so that it does not give an error?
error
Error (CS0115): 'Script_Instance.RunCommand(Rhino.RhinoDoc, Rhino.Commands.RunMode)': no suitable method found to override (line 63)
hatch boundray.gh (10.8 KB)


@Mahdiyar

You might consider using the hatch object GUID to reference it in Grasshopper like this.

private void RunScript(Guid id, ref object Outer, ref object Inner)
{
  var rhinoObject = RhinoDocument.Objects.FindId(id);
  if (rhinoObject is HatchObject)
  {
    var hatch = rhinoObject.Geometry as Hatch;
    Outer = hatch.Get3dCurves(true);
    Inner = hatch.Get3dCurves(false);
  }
}
import Rhino
rhino_object = Rhino.RhinoDoc.ActiveDoc.Objects.Find(id)
if type(rhino_object) is Rhino.DocObjects.HatchObject:
    hatch = rhino_object.Geometry
    Outer = hatch.Get3dCurves(True)
    Inner = hatch.Get3dCurves(False)

HatchBoundary.gh (7.4 KB)

4 Likes