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 !! ^^