Draw To Screen Space Foreground From DrawViewportWires

Hi @ThomasE,

to keep your dashboard consistently above the remaining 3d geometry you need to use the DrawForeground method. Here is what I did:

public override void BeforeRunScript()
  {
    _point.Clear();
    _box = BoundingBox.Empty;
    
    // Unregister & register new event
    Rhino.Display.DisplayPipeline.DrawForeground -= DrawForeground;
    Rhino.Display.DisplayPipeline.DrawForeground += DrawForeground;
  }


  public override BoundingBox ClippingBox
    {get{return _box;}}

  // Event function
  private void DrawForeground(object sender, Rhino.Display.DrawEventArgs e)
  {
    for (int i = 0; i < _point.Count; i++)
      DrawRec(e, _point[i]);
  }

  private void DrawRec(Rhino.Display.DrawEventArgs pipeline, Point3d point)
  {
    if (pipeline.Viewport.Id == pipeline.RhinoDoc.Views.ActiveView.ActiveViewportID)
    {
      Rectangle SQ = new Rectangle((int) point.X, (int) point.Y, 50, 50);
      pipeline.Display.Draw2dRectangle(SQ, Color.Black, 5, Color.LimeGreen);
    }
  }

This gets you 80% there. You will notice, however, that the dashboard is now persistent even if you remove the script from your document or switch to a different one. Ideally, you would unregister from the DrawForeground event handler in the following two cases but I only know how to do it from a compiled component. Maybe someone else can help you with the script component counterparts:

public override void DocumentContextChanged(GH_Document document, GH_DocumentContext context) {}

public override void RemovedFromDocument(GH_Document document) {}

image

drawForeground.gh (2.7 KB)

2 Likes