Delete layers from grasshopper

Any simple way to delete layers with specified names through grasshopper Vb.net or c#?

2023-12-28 14_18_55-Grasshopper - delete layer c#
delete layer c#.gh (4.8 KB)

  private void RunScript(string LayerName, bool GO)
  {
    if(wasgo & !GO){
      Guid id = this.RhinoDocument.Layers.FindName(LayerName).Id;
      this.RhinoDocument.Layers.Delete(id, true);
      wasgo = false;
    }else if(GO){
      wasgo = true;
    }
  }

  // <Custom additional code> 
  bool wasgo = false;
1 Like

hello it works only in item Access
how do we make for a list of layers

regards
rajeev

delete layer c# V0.2.gh (7.5 KB)

  private void RunScript(List<string> LayerNames, bool GO)
  {
    if(wasgo & !GO){
      foreach(string LayerName in LayerNames){
        Guid id = this.RhinoDocument.Layers.FindName(LayerName).Id;
        this.RhinoDocument.Layers.Delete(id, true);
      }
      wasgo = false;
    }else if(GO){
      wasgo = true;
    }
  }

  // <Custom additional code> 
  bool wasgo = false;

Consider trying Human plugin: Human | Food4Rhino , it should have components to manage layers.


Also, related How to delete a layer from GH?

1 Like

thank you so much