How to script to select/deselect grasshopper component with python or c#?

Hi guys, this might be basic question, but didn’t find any thread about it. The only one relevant is get true/false status if a component is selected by mouse.

So back to my question, how to use c# or python to select/deselect a grasshopper component on canvas? By “select”, I mean acting the same like using mouse to select component, and after operating the selected component turns green.

2023-09-17 19_21_25-Window
select by c#.gh (3.1 KB)

  private void RunScript(object x, bool y)
  {
    if(y){
      System.Guid id = this.Component.Params.Input[0].Sources[0].Attributes.DocObject.InstanceGuid;
      this.GrasshopperDocument.FindObject(id, true).Attributes.Selected = true;

      // this works too
      // this.Component.Params.Input[0].Sources[0].Attributes.Selected = true;
    }
  }
1 Like

Hi, Riccardo.

Seems like the same attribute could do both “show status of selection” and “set selection status” .

Thanks a lot, indeed.