Welcome to the Onshape forum! Ask questions and join in the discussions about everything Onshape.

First time visiting? Here are some places to start:
  1. Looking for a certain topic? Check out the categories filter or use Search (upper right).
  2. Need support? Ask a question to our Community Support category.
  3. Please submit support tickets for bugs but you can request improvements in the Product Feedback category.
  4. Be respectful, on topic and if you see a problem, Flag it.

If you would like to contact our Community Manager personally, feel free to send a private message or an email.

Alternative to lots of hidden feature params?

Evan_ReeseEvan_Reese Member Posts: 2,060 PRO
I'm doing a lot of UI logic that changes based on user selections. I'm doing it by using hidden boolean parameters and toggling them with editing logic. For example, the UI might look different depending on whether someone picks a vertex, edge, non-planar face, planar face, or nothing. My issue, is that there are getting to be quite a few of booleans. I also have some hidden integers for point indexes. I'd really love to be able to just have one hidden parameter that's a map of all of my booleans, then address it in the UI. I'd fill it with something like

{"pointIndex" : 1, "noSelection" : false, "isVertex" : false, "isEdge" : true, "isFace" : false, "isPlanarFace" : false}

Is there a way to do something like that? I can get by without it, but it just gets clickity-clackity to write, and fluffs up the code making it harder to read.
Evan Reese / Principal and Industrial Designer with Ovyl
Website: ovyl.io

Best Answers

  • NeilCookeNeilCooke Moderator, Onshape Employees Posts: 5,307
    Answer ✓
    You have to remember that the UI is a predicate so it cannot react to any logic created in the body of the script (apart from Editing Logic). 
    Senior Director, Technical Services, EMEAI
  • kevin_o_toole_1kevin_o_toole_1 Onshape Employees, Developers, HDM Posts: 565
    Answer ✓
    if (definition.UI.boolean1)
    {
        *Other parameters to show*
    }
    Yes, in order to get conditional visibility you need the booleans listed out explicitly. Our UI only has logic for dealing with those explicitly listed parameters. It sounds like you've made the simplest functional solution.

Answers

  • Evan_ReeseEvan_Reese Member Posts: 2,060 PRO
    I just realized I can probably use a hidden enum instead of a bunch of booleans for isVertex, isEdge etc. It would still be nice to have a single place to put all of the info that the UI references though.
    Evan Reese / Principal and Industrial Designer with Ovyl
    Website: ovyl.io
  • caden_armstrongcaden_armstrong Member, User Group Leader Posts: 127 ✭✭✭
    Closest solution you'd have would be to put all of the hidden parameters into a single predicate which gets called in your precondition.
    Functionally, I don't think it would really differ too much from having a hidden parameter map as you are suggesting,
    as in both cases you still need to have an if statement checking a map variable.

    If your biggest gripe is a messy precondition, moving it away into a precondition would at least organize things.
  • Evan_ReeseEvan_Reese Member Posts: 2,060 PRO
    That's a good idea, Caden. Thanks!
    Evan Reese / Principal and Industrial Designer with Ovyl
    Website: ovyl.io
  • kevin_o_toole_1kevin_o_toole_1 Onshape Employees, Developers, HDM Posts: 565
    You can also have a single "isAnything" field which contains a map/array/whatever data structure you want. That way you don't need to keep modifying the precondition to add new non-user-visible fields.
  • Evan_ReeseEvan_Reese Member Posts: 2,060 PRO
    edited June 2022
    You can also have a single "isAnything" field which contains a map/array/whatever data structure you want. That way you don't need to keep modifying the precondition to add new non-user-visible fields.
    Thanks, Kevin. I'd hoped that would work, but I'm not sure it's what I'm looking for. I'm wanting to hide and show UI parameters based on the contents, but it seems like I'm not able to access anything in the map. What I'd love to do is something like this:

    annotation { "Name" : "UI settings"}
    isAnything(definition.UI);

    then in my precondition something like

    if (definition.UI.boolean1)
    {
    *Other parameters to show*
    }

    I struggle with code formatting on the forums but here's an example script
    https://cad.onshape.com/documents/74b868c81ffd51b8b4a9c6a5/w/facc72e9362395db8a26dc6b/e/3cbb4cc8c851cbb31b6aa7b0
    Evan Reese / Principal and Industrial Designer with Ovyl
    Website: ovyl.io
  • NeilCookeNeilCooke Moderator, Onshape Employees Posts: 5,307
    Answer ✓
    You have to remember that the UI is a predicate so it cannot react to any logic created in the body of the script (apart from Editing Logic). 
    Senior Director, Technical Services, EMEAI
  • Evan_ReeseEvan_Reese Member Posts: 2,060 PRO
    NeilCooke said:
    You have to remember that the UI is a predicate so it cannot react to any logic created in the body of the script (apart from Editing Logic). 
    Yeah, I get that. I'd just hoped there would be a way to store a lot of booleans or enums inside of one isAnything param and access them, but I think I can't get inside of an array or map within the predicate. It seems like only booleans, enums, and lookup tables can drive visibility of other parameters. Is that right?
    Evan Reese / Principal and Industrial Designer with Ovyl
    Website: ovyl.io
  • kevin_o_toole_1kevin_o_toole_1 Onshape Employees, Developers, HDM Posts: 565
    Answer ✓
    if (definition.UI.boolean1)
    {
        *Other parameters to show*
    }
    Yes, in order to get conditional visibility you need the booleans listed out explicitly. Our UI only has logic for dealing with those explicitly listed parameters. It sounds like you've made the simplest functional solution.
  • Evan_ReeseEvan_Reese Member Posts: 2,060 PRO
    Thanks folks. For future readership, if you have a number of independent things to control in the UI via editing logic, use booleans. If you have a lot of mutually exclusive options, you can use an enum. You can't access anything in a container (i.e. map, array etc) within the precondition, so creating a map of booleans won't work.
    Evan Reese / Principal and Industrial Designer with Ovyl
    Website: ovyl.io
Sign In or Register to comment.