Pipeline by selected objects?

Hi,

In Grasshopper, instead of using Pipeline to get the objects from a layer is it possible to use something to get the objects that are currently selected and have them as input?

Thank you!

private void RunScript(ref object A)
  {
    if(!_init)
    {
      Rhino.RhinoDoc.SelectObjects -= RhinoDocOnSelectObjects;
      Rhino.RhinoDoc.SelectObjects += RhinoDocOnSelectObjects;
      Rhino.RhinoDoc.DeselectObjects -= RhinoDocOnSelectObjects;
      Rhino.RhinoDoc.DeselectObjects += RhinoDocOnSelectObjects;
      Rhino.RhinoDoc.DeselectAllObjects -= RhinoDocOnDeselectAllObjects;
      Rhino.RhinoDoc.DeselectAllObjects += RhinoDocOnDeselectAllObjects;
      _init = true;
    }
    A = objs;
  }

  // <Custom additional code> 
  private bool _init = false;
  List<GeometryBase> objs = new List<GeometryBase>();
  private void RhinoDocOnSelectObjects(object sender, RhinoObjectSelectionEventArgs e)
  {
    foreach(var rhObj in RhinoDoc.ActiveDoc.Objects.GetSelectedObjects(false, false))
      objs.Add(rhObj.Geometry);
    Component.ExpireSolution(true);
  }
  private void RhinoDocOnDeselectAllObjects(object sender, RhinoDeselectAllObjectsEventArgs e)
  {
    objs.Clear();
    Component.ExpireSolution(true);
  }

SelectedObjects.gh (13.3 KB)

Wow, this is so useful for quick geometry evaluation, checking areas, sketching. And fun to have such instant input.
Should be part of the Pipeline component. In GH2 maybe?

Fantastic solution!
Anyone knows how to translate this to python SDK mode?

Yes, I can only state once more that Pipeline Selected could be very useful, kind regards!

Could someone please change this code so it works in R8 and outputs GUIDs of selected objects?

This seems to work

using System;
using System.Collections;
using System.Collections.Generic;

using Rhino;
using Rhino.Geometry;

using Grasshopper;
using Grasshopper.Kernel;
using Grasshopper.Kernel.Data;
using Grasshopper.Kernel.Types;
using Rhino.DocObjects;
using System.Linq;

/// <summary>
/// This class will be instantiated on demand by the Script component.
/// </summary>
public class Script_Instance : GH_ScriptInstance
{
  private void Print(string text) { }
  private void Print(string format, params object[] args) { }
  private void Reflect(object obj) { }
  private void Reflect(object obj, string method_name) { }

  private readonly RhinoDoc RhinoDocument;
  private readonly GH_Document GrasshopperDocument;
  private readonly IGH_Component Component;
  private readonly int Iteration;

  private void RunScript(ref object A)
  {
    if (!_init)
    {
      Rhino.RhinoDoc.SelectObjects -= RhinoDocOnSelectObjects;
      Rhino.RhinoDoc.SelectObjects += RhinoDocOnSelectObjects;

      Rhino.RhinoDoc.DeselectObjects -= RhinoDocOnSelectObjects;
      Rhino.RhinoDoc.DeselectObjects += RhinoDocOnSelectObjects;

      Rhino.RhinoDoc.DeselectAllObjects -= RhinoDocOnDeselectAllObjects;
      Rhino.RhinoDoc.DeselectAllObjects += RhinoDocOnDeselectAllObjects;

      _init = true;
    }

    A = selectedGuids;
  }

  // <Custom additional code> 
  bool _init = false;
  List<Guid> selectedGuids = new List<Guid>();

  private void RhinoDocOnSelectObjects(object sender, RhinoObjectSelectionEventArgs e)
  {
    foreach (var rhObj in RhinoDoc.ActiveDoc.Objects.GetSelectedObjects(false, false))
    {
      Guid id = rhObj.Id;
      if (!selectedGuids.Contains(id))
        selectedGuids.Add(id);
    }

    Component.ExpireSolution(true);
  }

  private void RhinoDocOnDeselectAllObjects(object sender, RhinoDeselectAllObjectsEventArgs e)
  {
    selectedGuids.Clear();
    Component.ExpireSolution(true);
  }
  // </Custom additional code> 
}