How to make Two Boolean Toggles Reverse Each Other

Boolean Toggle (5.9 KB)

I want to make two boolean togggles reverse each other.
A) If toggle A is true, toggle B is false.If A is false, B is true.
B) If toggle B is true, toggle A is false.If B is false, A is true.

Currently, (A) works, but I have no idea how to make (B) work.
Can anybody help me with this issue?

You need to store the old A and B values to check which changed.
Also, you are not expiring the toggle components, so no other components will receive the change.

Try this:

 private void RunScript(bool Toggle_A, bool Toggle_B)
    Grasshopper.Kernel.Special.GH_BooleanToggle togA = (Grasshopper.Kernel.Special.GH_BooleanToggle) Component.Params.Input[0].Sources[0];
    Grasshopper.Kernel.Special.GH_BooleanToggle togB = (Grasshopper.Kernel.Special.GH_BooleanToggle) Component.Params.Input[1].Sources[0];
    if(togA.Value != TA){
      TA = togA.Value;
      TB = !togA.Value;
      togB.Value = TB;
    if(togB.Value != TB){
      TB = togB.Value;
      TA = !togB.Value;
      togA.Value = TA;

  // <Custom additional code> 
  public bool TA;
  public bool TB;
  // </Custom additional code> 

Note that expiring a component that is upstream of the c# itself will result in a sort of loop, throwing an error.
Like this seems stable (don’t know why) but I would totally expect further problems if you tweak it more.

1 Like

Metahopper can do that :+1:

Boolean Toggle (7.1 KB)

One toogle button is not enough ?

Thanks for your replay, inno
The reason I would use Boolen Toggle is because I want to clearly recognize which option I am using from RCP panel.
Your idea looks very nice. Thank you!.

Thanks!!. eddi

Thank for your quick replay, Ricardo.
I tried your scripting, but it’s not working. Uhmm…I don’t know why.
Probably seems like it should work…

Boolean Toggle (3.4 KB)

Maybe you didn’t put:

  // <Custom additional code> 
  public bool TA;
  public bool TB;
  // </Custom additional code> 

in the correct place…

Aha…! At last, it works.
Thank you so much !! ^^

@maje90 will your C# script work with more than two toggles? In a situation where only one toggle is true and all others switch to false?

Not that script. I did that for another goal.
But yes, you can do that too with c#.
Boolean Toggle list only one (4.3 KB)

@DavidRutten at first i tought this might be related to Value List component, but it isn’t, not fully.
2022-04-30 13_09_43-
If we will see Value List component on GH2, an option for “Radio button List” would be useful.
All other “form” of Value Lists component let the user select a single item out of a pre-made list…

1 Like

YES. It seems a radio button list is exactly the kind of functionality that @archist97 and I are looking for here—kind of surprising that this doesn’t exist as a simple component, either native in GH or from a third party.

Thank you so much, Riccrdo.
This is really handy !!