Rhino.Input.Custom.GetObject custom filters with grips

Hi all!
I’m trying to select grips of a specific SubD, one by one (to retain order).
Not grips of other objects.
Not more than one at once at time.

Problems:


custom filter.gh (23.1 KB)

Code for the top one:

  void SelectMultipleGrips(GH_Document doc){
    Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject();
    go.GeometryFilter = Rhino.DocObjects.ObjectType.Grip;
    go.SetCustomGeometryFilter(IsGripOwnedByGuid);
    go.SetCommandPrompt("Select grips");

    go.SubObjectSelect = false; //If you remove this row, IsGripOwnedByGuid filter won't work.
    go.OneByOnePostSelect = true;
    go.ChooseOneQuestion = true;

    go.GetMultiple(1, 0);

    objs = go.Objects();
    this.Component.ExpireSolution(true);
  }

  static System.Guid SubDId = new System.Guid();
  static bool IsGripOwnedByGuid(Rhino.DocObjects.RhinoObject obj, GeometryBase geo, ComponentIndex index){
    return ((Rhino.DocObjects.GripObject) obj).OwnerId.Equals(SubDId);
  }

Code for the bottom one:

  void SelectMultipleGrips(GH_Document doc){
    Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject();
    go.SetCustomGeometryFilter(NOTHING);

    go.GetMultiple(1, 0);

    objs = go.Objects();
    this.Component.ExpireSolution(true);
  }


  static bool NOTHING(Rhino.DocObjects.RhinoObject obj, GeometryBase geo, ComponentIndex index){
    return false;
  }

Hi Riccardo,

for Problem 1, you can temporarily disable the pickable control polygon like so:

import Rhino

def DoSomething():
    
    rhino_id = Rhino.RhinoApp.CurrentRhinoId
    settings = Rhino.PlugIns.PlugIn.GetPluginSettings(rhino_id, False)
    s = settings.GetChild("Options").GetChild("General")
    s.SetBool("PickableControlPolygon", False)
    
DoSomething()

I’d suggest to get the original value before your picker and restore it after your picker is done. I’m not sure about Problem 2 yet…

_
c.

1 Like

It seems to work only if I switch that bool on/off in a complete separate time than the execution of my code.
If I switch it to false, and then do a .GetObject() , I can still select the control polygon…

Hi Riccardo, does a small timeout help before ? I remember @Jarek having a similar issue when he temporarily changed a value using above method.

_
c.

Yeah… almost…
I’m using GrasshopperDocument.ScheduleSolution() and with a delay of 1000 it works 3 times out of 4… :confused:

Hi @maje90,

You might try just picking a single grip at a time - GetObject.Get - instead of multiple.

– Dale

1 Like

That make sense!
It gives me a good “Cannot use these objects. Removing them from selection.” and lets me retry the selection.
Thanks!

@maje90 - maybe something like the attached.

TestRiccardo.cs (1.8 KB)

– Dale

1 Like

Thank you for the example with also the correct grammar and proper use.
I’ll use this a start point for my other .Get cases.
Thanks!