Zebra Stripes in Grasshopper with C#

Hello,

I’m trying to make a quick C# component that does a Zebra Stripes preview of a brep. Nothing I do with DisplayPipeline or DrawZebraPreview works at all. Surely it should be something like:

Rhino.Display.DisplayPipeline.DrawZebraPreview(brep, Color.White);

Any help gratefully received!

you can do it with a display conduit.
the following should get you started.
but only started - no clean up - and you might end up with multiple conduits running …
really - just a fast and dirty starting point:

// Grasshopper Script Instance
#region Usings
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Drawing;

using Rhino;
using Rhino.Geometry;
using Rhino.Display;

using Grasshopper;
using Grasshopper.Kernel;
using Grasshopper.Kernel.Data;
using Grasshopper.Kernel.Types;
#endregion

public class Script_Instance : GH_ScriptInstance
{
    #region Notes
    /* 
      Members:
        RhinoDoc RhinoDocument
        GH_Document GrasshopperDocument
        IGH_Component Component
        int Iteration

      Methods (Virtual & overridable):
        Print(string text)
        Print(string format, params object[] args)
        Reflect(object obj)
        Reflect(object obj, string method_name)
    */
    #endregion
    private ZebraConduit myZebra;
    private void RunScript(Brep brep, bool enable, ref object a)
    {
        if (myZebra == null)
        {
            myZebra = new ZebraConduit();
        }
        myZebra.Brep = brep;
        myZebra.Enabled = enable;
        // Write your logic here
        a = null;
    }
}


public class ZebraConduit : Rhino.Display.DisplayConduit
{
    private Brep _brep;
    private BoundingBox _bbox;

    public Brep Brep 
    {
        set {
            _brep = value;
            _bbox = _brep.GetBoundingBox(true);
        }
    }
  protected override void CalculateBoundingBox(CalculateBoundingBoxEventArgs e)
  {
    base.CalculateBoundingBox(e);
    e.IncludeBoundingBox(_bbox);
  }
 
  protected override void PreDrawObjects(DrawEventArgs e)
  {
    base.PreDrawObjects(e);
    e.Display.DrawZebraPreview(_brep, Color.White);;
  }
}

(EDIT)
@Ashley_Cichocki here is the file
ZebraConduit_00.gh (10.3 KB)

more infos here:

2 Likes

Wow Tom, that’s great! Thanks for the link too, this opens a whole new avenue of Rhino I had no idea we could access.

How would I know if I had multiple conduits running? I’m guess when you disable the component, it no longer effects the conduit… or is that another naive thing to say?

(Edit) Sometimes it doesn’t turn off, I guess that’s how I’d know.

Quick Update:

I managed it in the end by just converting and adjusting a VB definition posted by @DavidRutten Surface curvature analysis, like "zebra" in Rhino - Grasshopper

You will have to edit line 63 and set filepath to the location that you are keeping ‘zebra.png’.

By editing the zebra.png file. I’m thinking of adding a slider that flips between a range of files in order to adjust the thickness/spacing of the lines.

zebra
zebra.gh (6.3 KB)

(Also this discussion was useful: 'Zebra' in Grasshopper - #2 by laurent_delrieu)