Displaying curves before adding them to the document

Hi all,

I have been struggling with this for a while and can’t quite get my head around the script’s behaviour.

Essentially, in previous code, I have joined a bunch of curves via
Curve joined = Curve.JoinCurves(crvsToJoin.ToArray(), RhinoMath.ZeroTolerance); These curves are derived from previous scripting working similarly to the SelChain command. The essential difference is that when the user picks the chain, the command should automatically join it and discard the ‘used curves’ (so that there aren’t any duplicates). No problem up until here.

Ideally, I would like to add the joined curve to the display so the user can verify it first, and then press enter if they want to confirm. Only then will the script add the joined curve to the document and delete the curves ‘used’ to make the joined curve. To do this, I have written the following code:

         Curve[] joined = Curve.JoinCurves(crvsToJoin.ToArray(), RhinoMath.ZeroTolerance);

         display.AddCurve(joined[0], color, thickness);
         view.Redraw();

         string input = string.Empty;
         var result = Rhino.Input.RhinoGet.GetString("Premi Enter per confermare la Selezione.", true, ref input);
         if (result == Result.Success)
         {
             Guid joinedCrvId = doc.Objects.AddCurve(joined[0]);
             ObjRef joinedCrvObjRef = new ObjRef(doc, joinedCrvId);
             doc.Objects.Delete(doc.Objects.Find(pickedcrvID));
             display.Dispose();  
             curvaConcatenata = joinedCrvObjRef;
             return true;
         }
         else
         {
             display.Dispose();
             return false; 
         }

This code will not add the joined curve to the document and neither will it delete the curve that was originally picked by the user to trigger the chain selection.

Tinkering, I have found a solution which sort of works:

            Curve[] joined = Curve.JoinCurves(crvsToJoin.ToArray(), RhinoMath.ZeroTolerance);

            Guid joinedCrvId = doc.Objects.AddCurve(joined[0]);
            ObjRef joinedCrvObjRef = new ObjRef(doc,joinedCrvId);
            display.AddCurve(joined[0], color, thickness);
            view.Redraw();
            doc.Objects.Delete(doc.Objects.Find(pickedcrvID));

            string input = string.Empty;
            var result = Rhino.Input.RhinoGet.GetString("Premi Enter per confermare la Selezione.", true, ref input);
            if (result == Result.Success)
            {
                display.Dispose();  
                curvaConcatenata = joinedCrvObjRef;
                return true;
            }
            else
            {
                display.Dispose();
                return false; 
            }

The caveat here is that if the users presses escape while the command is running, it still adds the curve and deletes the originally picked curve. What am I not seeing?

Thanks

Hi @nicolocostan99 ,
I believe this would be more appropriate for your goal
https://developer.rhino3d.com/api/rhinocommon/rhino.display.displayconduit

Farouk

Seems interesting but, as I’m fairly new to Rhinocommon, I’m unsure as to what this does, how to implement it and when to use it over CustomDisplay.

@nicolocostan99 Rhino - Display Conduit Arrowheads

class DrawArrowHeadsConduit : Rhino.Display.DisplayConduit
{
  private readonly Line m_line;
  private readonly int m_screen_size;
  private readonly double m_world_size;
 
  public DrawArrowHeadsConduit(Line line, int screenSize, double worldSize)
  {
    m_line = line;
    m_screen_size = screenSize;
    m_world_size = worldSize;
  }
 
  protected override void DrawForeground(Rhino.Display.DrawEventArgs e)
  {
    e.Display.DrawArrow(m_line, System.Drawing.Color.Black, m_screen_size, m_world_size);
  }
}
 
partial class Examples
{
  static DrawArrowHeadsConduit m_draw_conduit;
 
  public static Result ConduitArrowHeads(RhinoDoc doc)
  {
    if (m_draw_conduit != null)
    {
      RhinoApp.WriteLine("Turn off existing arrowhead conduit");
      m_draw_conduit.Enabled = false;
      m_draw_conduit = null;
    }
    else
    {
      // get arrow head size
      var go = new GetOption();
      go.SetCommandPrompt("ArrowHead length in screen size (pixels) or world size (percentage of arrow length)?");
      go.AddOption("screen");
      go.AddOption("world");
      go.Get();
      if (go.CommandResult() != Result.Success)
        return go.CommandResult();
 
      int screen_size = 0;
      double world_size = 0.0;
      if (go.Option().EnglishName == "screen")
      {
        var gi = new GetInteger();
        gi.SetLowerLimit(0, true);
        gi.SetCommandPrompt("Length of arrow head in pixels");
        gi.Get();
        if (gi.CommandResult() != Result.Success)
          return gi.CommandResult();
        screen_size = gi.Number();
      }
      else
      {
        var gi = new GetInteger();
        gi.SetLowerLimit(0, true);
        gi.SetUpperLimit(100, false);
        gi.SetCommandPrompt("Length of arrow head in percentage of total arrow length");
        gi.Get();
        if (gi.CommandResult() != Result.Success)
          return gi.CommandResult();
        world_size = gi.Number() / 100.0;
      }
 
 
      // get arrow start and end points
      var gp = new GetPoint();
      gp.SetCommandPrompt("Start of line");
      gp.Get();
      if (gp.CommandResult() != Result.Success)
        return gp.CommandResult();
      var start_point = gp.Point();
 
      gp.SetCommandPrompt("End of line");
      gp.SetBasePoint(start_point, false);
      gp.DrawLineFromPoint(start_point, true);
      gp.Get();
      if (gp.CommandResult() != Result.Success)
        return gp.CommandResult();
      var end_point = gp.Point();
 
      var v = end_point - start_point;
      if (v.IsTiny(Rhino.RhinoMath.ZeroTolerance))
        return Result.Nothing;
 
      var line = new Line(start_point, end_point);
 
      m_draw_conduit = new DrawArrowHeadsConduit(line, screen_size, world_size);
      // toggle conduit on/off
      m_draw_conduit.Enabled = true;
      RhinoApp.WriteLine("Draw arrowheads conduit enabled.");
    }
    doc.Views.Redraw();
    return Result.Success;
  }
}

Displayconduits are really handy when it comes to displaying object previews.