BOOLEAN IN UI

papawo
papawo Member, Developers Posts: 206 PRO
I have 2 boolean selection in UI.
How to inactivate other boolean  if user selected other one?
Tagged:

Best Answer

Answers

  • kevin_o_toole_1
    kevin_o_toole_1 Onshape Employees, Developers, HDM Posts: 565 image
    You can make a parameter appear conditionally based on other parameters by defining them inside an if statement, like so:
    annotation { "Name" : "Boolean 1" }
            definition.boolean1 is boolean;
    
            if (!definition.boolean1) {
                annotation { "Name" : "Boolean 2" }
                definition.boolean2 is boolean;
            }         

  • papawo
    papawo Member, Developers Posts: 206 PRO
    edited November 2016
    how to make boolean1 disappear if boolean2 is chosen?
  • kevin_o_toole_1
    kevin_o_toole_1 Onshape Employees, Developers, HDM Posts: 565 image
    Unfortunately there's no way to do that right now. Inputs can only control visibility of other inputs below them, not above them.

  • john_f_carr
    john_f_carr Onshape Employees Posts: 74 image
    If you have three valid states (false+false, false+true, true+false) you can use an enumeration instead of a pair of booleans.
  • mahir
    mahir Member, Developers Posts: 1,324 ✭✭✭✭✭
    I forgot what it's called exactly, but there is a new Horizontal_UI_Hint option that lets you list an enumeration as a row of mutually exclusive horizontal buttons. This seems well suited to your purpose.
  • papawo
    papawo Member, Developers Posts: 206 PRO
    @john_f_carr - can you do an example?
  • kevin_o_toole_1
    kevin_o_toole_1 Onshape Employees, Developers, HDM Posts: 565 image
    If your boolean options are, for instance, "With square hole" or "With round hole", you can instead have a dropdown menu (an enum) with choices for hole type "None", "Square", or "Round".

    Here's a simple example feature doing this:
    https://cad.onshape.com/documents/d23d3f02d297f1a626d988ff/w/f7169c9d20aac5513724f724/e/1a5ba32207c8142eba85d86e




  • papawo
    papawo Member, Developers Posts: 206 PRO
    edited November 2016
    @kevin_o_toole_1 -   that is great but what I am aiming to do is similar below. I wanted the user to pick only one option and when he does other option will disappear or disabled . Main 2 booleans will only appear if nothing is selected or 1 boolean were unselect.

    https://cad.onshape.com/documents/583de44c545b20104cad6da9/w/3c81f383481ff03c72213fc0/e/1743674a7d5a5a04c35b645d

  • papawo
    papawo Member, Developers Posts: 206 PRO
    edited November 2016
    the 2 boolean are separate choices with separate features for specific part.
    if user pick boolean 1 it must be for part1 and it will cut a "square", and if boolean 2 , it must be for part 2 and it will cut a "triangle"
    interchanging will be wrong .


    i want user to pick 1 of the 2 boolean only . and then use the same featurescript again for the other part.

    but if this is impossible. the nearest thing i can do is the horizontal row sample you did, unless you have more idea under your sleeve.  :)

  • mahir
    mahir Member, Developers Posts: 1,324 ✭✭✭✭✭
    The nature of FeatureScripts is that you can go back and make changes just like a regular feature. What you're looking to do is contrary to that workflow. If a user wanted option 1 but clicked option 2 by accident, he'd have to exit the feature and start again. This doesn't sound very user friendly. I'd stick to an enum, either dropdown or horizontal.
  • papawo
    papawo Member, Developers Posts: 206 PRO
    @mahir ---  If a user wanted option 1 but clicked option 2 by accident, he'd have to exit the feature and start again. 

    user can still go back by unclicking either of the boolean.

    but anyway..i guess i will go with the horizontal..

    thanks people.  :)