Grasshopper - Move objects to a new layer

I need to move some objects resulted from a sort operation of the actual objects from Rhino view-port to a different layer using Grasshopper and I can’t find a way to do this.

Basically I’m using a script that selects all the circles with the diameter of 75mm from my actual .3dm document and I need to move all of them to a new layer called “Holes”.

Move_selected_objects_to_new_layer.gh (3.7 KB)

Hi Macuso,
Your script is good, you were almost there.

You don’t need an output list or such.

(I used “circles” instead of “Holes” … it should work)
Move_selected_objects_to_new_layer_re
Move_selected_objects_to_new_layer_re.gh (8.1 KB)

private void RunScript(double diameter, string name)
  {
    Rhino.DocObjects.RhinoObject[] rhinoObj = Rhino.RhinoDoc.ActiveDoc.Objects.FindByObjectType(Rhino.DocObjects.ObjectType.Curve);
    int index = Rhino.RhinoDoc.ActiveDoc.Layers.FindName(name).Index;
    foreach(Rhino.DocObjects.CurveObject obj in rhinoObj){
      if (obj.CurveGeometry.IsCircle() == true){
        Rhino.Geometry.Circle temp = new Rhino.Geometry.Circle(0);
        obj.CurveGeometry.TryGetCircle(out temp);
        if (temp.Diameter == diameter){
          obj.Attributes.LayerIndex = index;
          obj.CommitChanges();
        }
      }
    }

Hi Riccardo.

Thank you for reply. Your solution don’t address my needs. I need to move the selected circles to a new layer. Delete the selected objects from the actual rhino document default layer and move them to a new layer, “Circles” or “Holes” or whatever just to don’t be on “Default” layer.

Perhaps you should learn programming at least as much as to be able to read the code. And not just use it as it is. In the code above you have all the information you need.

Also you do not need to delete objects from a layer to move them to another layer. The objects are the same. You simply change their layer.