maje90
(Riccardo Majewski)
September 30, 2022, 9:46am
1
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;
}
clement
September 30, 2022, 7:36pm
2
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
maje90
(Riccardo Majewski)
September 30, 2022, 8:52pm
3
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…
clement
September 30, 2022, 8:57pm
4
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.
maje90
(Riccardo Majewski)
September 30, 2022, 9:06pm
5
Yeah… almost…
I’m using GrasshopperDocument.ScheduleSolution() and with a delay of 1000 it works 3 times out of 4…
dale
(Dale Fugier)
September 30, 2022, 9:10pm
6
Hi @maje90 ,
You might try just picking a single grip at a time - GetObject.Get - instead of multiple.
– Dale
1 Like
maje90
(Riccardo Majewski)
September 30, 2022, 9:13pm
7
That make sense!
It gives me a good “Cannot use these objects. Removing them from selection.” and lets me retry the selection.
Thanks!
dale
(Dale Fugier)
September 30, 2022, 9:40pm
8
@maje90 - maybe something like the attached.
TestRiccardo.cs (1.8 KB)
– Dale
1 Like
maje90
(Riccardo Majewski)
October 2, 2022, 11:40am
9
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!