Can DrawViewportWires draw GH objects?

OK, so I’m trying to override the DrawViewportWires in a C# script component, but it seems the method is never called.

Are there any render modes, settings or any other explicit preconditions that needs to be met before the DrawViewportWires is actually called?

I.m calling “RhinoApp.WriteLine(“Custom Drawing…”);” from the DrawViewportWires method to debug if the method is called, but no such text shows in the command history window.

The relevant code (I am setting the data lists in the RunScript method):

  private void RunScript(...)
  {
    // ======
    // DISPLAY
    // ======
    m_cloud = new PointCloud(m_chain.m_ikjoints);
    m_display_lines = m_chain.GetSegmentLines();
    
// <additional code>

  BoundingBox m_bbx;
  Line[] m_display_lines;
  PointCloud m_cloud;
  public override void BeforeRunScript()
  {
    m_bbx = BoundingBox.Empty;
    m_display_lines = null;
    m_cloud = null;
  }
  public override BoundingBox ClippingBox {
    get {
      m_bbx = new BoundingBox(new Point3d(-100, -100, -100), new Point3d(100, 100, 100));
      return m_bbx;
    }
  }
  public override void DrawViewportWires(IGH_PreviewArgs args)
  {
    RhinoApp.WriteLine("Custom Drawing...");    
    if (Component.Hidden) return;
    if (m_cloud != null) 
    {   
      float radius = 0.2f;
      args.Display.DrawPointCloud(m_cloud, radius);
    }
    if (m_display_lines == null)  return;
    args.Display.DrawLines(m_display_lines, Color.Black);
  }
  // </Custom additional code> 
}

Nothing happens. Why? Can only Rhon objects be weritten? The objects in my lists (points and lines) are only GH objects not baked into Rhino.

// Rolf

Does your C# component have any inputs or outputs? I noticed that if the component has no drawable parameters it will never even attempt to draw itself.

This works though: csharpdisplay.gh (2.1 KB)

Yes, it has both inputs and outputs (the component currently in “maintenance mode”…)

bild

// Rolf

It would probably be handy to know what the error is you’re getting. Might be relevant.

Nah, It just broke while I’m in the middle of a heavy refactoring. In a minute or two, or a hundred, I’ll be back up running.

// Rolf

Edit: OK, @DavidRutten, now I’m back again after doing some refactoring. The component now compiles, but still nothing is drawn by the draw method (so I used CustomPreview for now, Disable them and then nothing at all is drawn).

The files. The main script is as simple as heart’s desire, so I have no clue about what could be the problem:

IK definitions.3dm (457.6 KB)
Edit: Updated/fixed version (0.4):
IK Inverse Kinematic Segments.gh (35.1 KB)

@DavidRutten,
Although no panic (so far only experimental, but soon…) - Any clues?

// Rolf

You’ve switched the preview off on your component. Are you sure that’s not the problem?

Yeah, that definitely is the problem. If I enable the preview your chain starts showing up. I changed your lines from 1-pixel black lines to 5-pixel pink ones, and they’re right there:

If you don’t want your output parameters to also show their preview, then you must hide them individually, but disabling the preview for the whole component does exactly what it claims on the tin.

    foreach (var param in Component.Params.Output)
    {
      IGH_PreviewObject prv = param as IGH_PreviewObject;
      if (prv != null)
        prv.Hidden = true;
    }

Haha, the only thing I didn’t try. Too far-fetched I guess… :wink:

Many thanks!

// Rolf