Grasshopper component wire display dependent on distance between components / length of wire

Is this somehow possible? Because that’s basically my criterium for making them visible or hidden.

you could hack this with metahopper…

wire-display-by-distance.gh (15.8 KB)

3 Likes

private void RunScript(bool active, int d)
{
  if(!active) return;
  _d = d;
  foreach(var obj in GrasshopperDocument.ActiveObjects())
  {
    if(obj is IGH_Param)
      HideLongWire((IGH_Param) obj);
    else if(obj is IGH_Component)
    {
      var comp = (IGH_Component) obj;
      foreach(var param in comp.Params)
        HideLongWire(param);
    }
  }
}
// <Custom additional code> 
int _d = 1000;
void HideLongWire(IGH_Param param)
{
  var tPivot = param.Attributes.Pivot;
  foreach(var s in param.Sources)
  {
    var sPivot = s.Attributes.Pivot;
    var d = Math.Sqrt(Math.Pow((sPivot.X - tPivot.X), 2) + Math.Pow((sPivot.Y - tPivot.Y), 2));
    if (d > _d)
    {
      param.WireDisplay = (GH_ParamWireDisplay) 0;
      continue;
    }
    param.WireDisplay = (GH_ParamWireDisplay) 2;
    return;
  }
}
// </Custom additional code> 

Wire.gh (7.0 KB)

6 Likes

thanks for both options. I like the compact solution @Mahdiyar posted.

There are 2 issues:

  • it doesn’t work on relays
  • all my telepathy components get affected. How do I cancel these from being selected?

found this one by selecting them out with (obj.Name != “Remote Receiver”)

1 Like

private void RunScript(bool active, int d)
{
  if(!active) return;
  _d = d;
  foreach(var obj in GrasshopperDocument.ActiveObjects())
  {
    if(obj.Name == "Remote Receiver") continue;
    if(obj is IGH_Param)
      HideLongWire((IGH_Param) obj);
    else if(obj is IGH_Component)
    {
      var comp = (IGH_Component) obj;
      foreach(var param in comp.Params)
        HideLongWire(param);
    }
  }
}
// <Custom additional code> 
int _d = 1000;
void HideLongWire(IGH_Param param)
{
  var tPivot = param.Attributes.Pivot;
  foreach(var s in param.Sources)
  {
    var sPivot = s.Attributes.Pivot;
    var d = Math.Sqrt(Math.Pow((sPivot.X - tPivot.X), 2) + Math.Pow((sPivot.Y - tPivot.Y), 2));
   if (d < _d)
    {
      param.WireDisplay = (GH_ParamWireDisplay) 0;
      continue;
    }
    param.WireDisplay = (GH_ParamWireDisplay) 2;
    return;
  }
}
// </Custom additional code> 

Wire.gh (10.1 KB)

8 Likes